getting_started_controller_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. require 'rails_helper'
  2. RSpec.describe GettingStartedController do
  3. describe '.validate_uri' do
  4. it 'false for nil' do
  5. expect(described_class.validate_uri(nil)).to be_falsey
  6. end
  7. it 'false for empty' do
  8. expect(described_class.validate_uri('')).to be_falsey
  9. end
  10. it 'false for non-http(s)' do
  11. expect(described_class.validate_uri('a://example.org')).to be_falsey
  12. end
  13. it 'false for gibberish uri' do
  14. expect(described_class.validate_uri('http:///a')).to be_falsey
  15. end
  16. it 'http and fqdn for http' do
  17. expect(described_class.validate_uri('http://example.org')).to eq({ scheme: 'http', fqdn: 'example.org' })
  18. end
  19. it 'https and fqdn for https' do
  20. expect(described_class.validate_uri('https://example.org')).to eq({ scheme: 'https', fqdn: 'example.org' })
  21. end
  22. it 'http and fqdn for http on default port' do
  23. expect(described_class.validate_uri('http://example.org:80')).to eq({ scheme: 'http', fqdn: 'example.org' })
  24. end
  25. it 'https and fqdn for https on default port' do
  26. expect(described_class.validate_uri('https://example.org:443')).to eq({ scheme: 'https', fqdn: 'example.org' })
  27. end
  28. it 'http and fqdn with port for http on custom port' do
  29. expect(described_class.validate_uri('http://example.org:443')).to eq({ scheme: 'http', fqdn: 'example.org:443' })
  30. end
  31. it 'https and fqdn with port for https on custom port' do
  32. expect(described_class.validate_uri('https://example.org:80')).to eq({ scheme: 'https', fqdn: 'example.org:80' })
  33. end
  34. end
  35. end