url_information_spec.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe UrlInformation, :aggregate_failures do
  4. subject(:url_information) { described_class.new(url) }
  5. let(:url) { nil }
  6. describe '.fqdn' do
  7. it 'not filled when not valid' do
  8. expect { url_information }.to raise_error(UrlInformation::Error)
  9. end
  10. context 'with valid url' do
  11. let(:url) { 'http://example.org' }
  12. it 'fqdn and scheme' do
  13. expect(url_information.fqdn).to eq 'example.org'
  14. expect(url_information.scheme).to eq 'http'
  15. end
  16. end
  17. context 'with https url' do
  18. let(:url) { 'https://example.org' }
  19. it 'fqdn and scheme' do
  20. expect(url_information.fqdn).to eq 'example.org'
  21. expect(url_information.scheme).to eq 'https'
  22. end
  23. end
  24. context 'with http and fqdn for http on default port' do
  25. let(:url) { 'http://example.org:80' }
  26. it 'fqdn and scheme' do
  27. expect(url_information.fqdn).to eq 'example.org'
  28. expect(url_information.scheme).to eq 'http'
  29. end
  30. end
  31. context 'with https and fqdn for https on default port' do
  32. let(:url) { 'https://example.org:443' }
  33. it 'fqdn and scheme' do
  34. expect(url_information.fqdn).to eq 'example.org'
  35. expect(url_information.scheme).to eq 'https'
  36. end
  37. end
  38. context 'with https and fqdn with custom port' do
  39. let(:url) { 'https://example.org:5555' }
  40. it 'fqdn and scheme' do
  41. expect(url_information.fqdn).to eq 'example.org:5555'
  42. expect(url_information.scheme).to eq 'https'
  43. end
  44. end
  45. end
  46. end