You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.6 KiB

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