email_domain_block_spec.rb 1.4 KB

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