tag_manager_spec.rb 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe TagManager do
  4. describe '#local_domain?' do
  5. # The following comparisons MUST be case-insensitive.
  6. around do |example|
  7. original_local_domain = Rails.configuration.x.local_domain
  8. Rails.configuration.x.local_domain = 'domain.example.com'
  9. example.run
  10. Rails.configuration.x.local_domain = original_local_domain
  11. end
  12. it 'returns true for nil' do
  13. expect(described_class.instance.local_domain?(nil)).to be true
  14. end
  15. it 'returns true if the slash-stripped string equals to local domain' do
  16. expect(described_class.instance.local_domain?('DoMaIn.Example.com/')).to be true
  17. end
  18. it 'returns false for irrelevant string' do
  19. expect(described_class.instance.local_domain?('DoMaIn.Example.com!')).to be false
  20. end
  21. end
  22. describe '#web_domain?' do
  23. # The following comparisons MUST be case-insensitive.
  24. around do |example|
  25. original_web_domain = Rails.configuration.x.web_domain
  26. Rails.configuration.x.web_domain = 'domain.example.com'
  27. example.run
  28. Rails.configuration.x.web_domain = original_web_domain
  29. end
  30. it 'returns true for nil' do
  31. expect(described_class.instance.web_domain?(nil)).to be true
  32. end
  33. it 'returns true if the slash-stripped string equals to web domain' do
  34. expect(described_class.instance.web_domain?('DoMaIn.Example.com/')).to be true
  35. end
  36. it 'returns false for string with irrelevant characters' do
  37. expect(described_class.instance.web_domain?('DoMaIn.Example.com!')).to be false
  38. end
  39. end
  40. describe '#normalize_domain' do
  41. it 'returns nil if the given parameter is nil' do
  42. expect(described_class.instance.normalize_domain(nil)).to be_nil
  43. end
  44. it 'returns normalized domain' do
  45. expect(described_class.instance.normalize_domain('DoMaIn.Example.com/')).to eq 'domain.example.com'
  46. end
  47. end
  48. describe '#local_url?' do
  49. around do |example|
  50. original_web_domain = Rails.configuration.x.web_domain
  51. example.run
  52. Rails.configuration.x.web_domain = original_web_domain
  53. end
  54. it 'returns true if the normalized string with port is local URL' do
  55. Rails.configuration.x.web_domain = 'domain.example.com:42'
  56. expect(described_class.instance.local_url?('https://DoMaIn.Example.com:42/')).to be true
  57. end
  58. it 'returns true if the normalized string without port is local URL' do
  59. Rails.configuration.x.web_domain = 'domain.example.com'
  60. expect(described_class.instance.local_url?('https://DoMaIn.Example.com/')).to be true
  61. end
  62. it 'returns false for string with irrelevant characters' do
  63. Rails.configuration.x.web_domain = 'domain.example.com'
  64. expect(described_class.instance.local_url?('https://domain.example.net/')).to be false
  65. end
  66. end
  67. end