email_domain_block_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe EmailDomainBlock do
  4. describe 'block?' do
  5. let(:input) { nil }
  6. context 'when given an e-mail address' do
  7. let(:input) { "foo@#{domain}" }
  8. context 'with a top level domain' do
  9. let(:domain) { 'example.com' }
  10. it 'returns true if the domain is blocked' do
  11. Fabricate(:email_domain_block, domain: 'example.com')
  12. expect(described_class.block?(input)).to be true
  13. end
  14. it 'returns false if the domain is not blocked' do
  15. Fabricate(:email_domain_block, domain: 'other-example.com')
  16. expect(described_class.block?(input)).to be false
  17. end
  18. end
  19. context 'with a subdomain' do
  20. let(:domain) { 'mail.example.com' }
  21. it 'returns true if it is a subdomain of a blocked domain' do
  22. Fabricate(:email_domain_block, domain: 'example.com')
  23. expect(described_class.block?(input)).to be true
  24. end
  25. end
  26. end
  27. context 'when given an array of domains' do
  28. let(:input) { %w(foo.com mail.foo.com) }
  29. it 'returns true if the domain is blocked' do
  30. Fabricate(:email_domain_block, domain: 'mail.foo.com')
  31. expect(described_class.block?(input)).to be true
  32. end
  33. end
  34. end
  35. end