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.

47 lines
1.5 KiB

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