Use validation matchers for `UserEmailValidator` spec (#37908)

pull/37920/head
Matt Jankowski 5 days ago committed by GitHub
parent c118ff708f
commit 2a9de97cb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3,49 +3,25 @@
require 'rails_helper'
RSpec.describe UserEmailValidator do
describe '#validate' do
subject { described_class.new.validate(user) }
subject { Fabricate.build :user, confirmed_at: nil }
let(:user) { instance_double(User, email: 'info@mail.com', sign_up_ip: '1.2.3.4', errors: errors) }
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
let(:email_address) { 'info@host.example' }
before do
allow(user).to receive(:valid_invitation?).and_return(false)
allow(EmailDomainBlock).to receive(:block?) { blocked_email }
end
context 'when email provider is blocked' do
before { Fabricate :email_domain_block, domain: 'host.example' }
context 'when e-mail provider is blocked' do
let(:blocked_email) { true }
it 'adds error' do
subject
expect(errors).to have_received(:add).with(:email, :blocked).once
end
end
context 'when e-mail provider is not blocked' do
let(:blocked_email) { false }
it 'does not add errors' do
subject
expect(errors).to_not have_received(:add)
end
it { is_expected.to_not allow_value(email_address).for(:email).with_message(:blocked) }
end
context 'when canonical e-mail is blocked' do
let(:other_user) { Fabricate(:user, email: 'i.n.f.o@mail.com') }
context 'when email provider is not blocked' do
it { is_expected.to allow_value(email_address).for(:email) }
end
before do
other_user.account.suspend!
end
context 'when canonical email address is blocked' do
let(:other_user) { Fabricate(:user, email: 'i.n.f.o@host.example') }
it 'adds error' do
subject
before { other_user.account.suspend! }
expect(errors).to have_received(:add).with(:email, :taken).once
end
end
end
it { is_expected.to_not allow_value(email_address).for(:email).with_message(:taken) }
end
end

Loading…
Cancel
Save