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