user_email_validator_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe UserEmailValidator do
  4. describe '#validate' do
  5. subject { described_class.new.validate(user) }
  6. let(:user) { instance_double(User, email: 'info@mail.com', sign_up_ip: '1.2.3.4', errors: errors) }
  7. let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
  8. before do
  9. allow(user).to receive(:valid_invitation?).and_return(false)
  10. allow(EmailDomainBlock).to receive(:block?) { blocked_email }
  11. end
  12. context 'when e-mail provider is blocked' do
  13. let(:blocked_email) { true }
  14. it 'adds error' do
  15. subject
  16. expect(errors).to have_received(:add).with(:email, :blocked).once
  17. end
  18. end
  19. context 'when e-mail provider is not blocked' do
  20. let(:blocked_email) { false }
  21. it 'does not add errors' do
  22. subject
  23. expect(errors).to_not have_received(:add)
  24. end
  25. context 'when canonical e-mail is blocked' do
  26. let(:other_user) { Fabricate(:user, email: 'i.n.f.o@mail.com') }
  27. before do
  28. other_user.account.suspend!
  29. end
  30. it 'adds error' do
  31. subject
  32. expect(errors).to have_received(:add).with(:email, :taken).once
  33. end
  34. end
  35. end
  36. end
  37. end