canonical_email_block_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe CanonicalEmailBlock do
  4. describe '#email=' do
  5. let(:target_hash) { '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b' }
  6. it 'sets canonical_email_hash' do
  7. subject.email = 'test@example.com'
  8. expect(subject.canonical_email_hash).to eq target_hash
  9. end
  10. it 'sets the same hash even with dot permutations' do
  11. subject.email = 't.e.s.t@example.com'
  12. expect(subject.canonical_email_hash).to eq target_hash
  13. end
  14. it 'sets the same hash even with extensions' do
  15. subject.email = 'test+mastodon1@example.com'
  16. expect(subject.canonical_email_hash).to eq target_hash
  17. end
  18. it 'sets the same hash with different casing' do
  19. subject.email = 'Test@EXAMPLE.com'
  20. expect(subject.canonical_email_hash).to eq target_hash
  21. end
  22. end
  23. describe '.block?' do
  24. let!(:canonical_email_block) { Fabricate(:canonical_email_block, email: 'foo@bar.com') }
  25. it 'returns true for the same email' do
  26. expect(described_class.block?('foo@bar.com')).to be true
  27. end
  28. it 'returns true for the same email with dots' do
  29. expect(described_class.block?('f.oo@bar.com')).to be true
  30. end
  31. it 'returns true for the same email with extensions' do
  32. expect(described_class.block?('foo+spam@bar.com')).to be true
  33. end
  34. it 'returns false for different email' do
  35. expect(described_class.block?('hoge@bar.com')).to be false
  36. end
  37. end
  38. end