2018-12-29 06:23:44 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe BlacklistedEmailValidator, type: :validator do
|
|
|
|
describe '#validate' do
|
2022-02-24 16:28:23 +00:00
|
|
|
let(:user) { double(email: 'info@mail.com', sign_up_ip: '1.2.3.4', errors: errors) }
|
2018-12-29 06:23:44 +00:00
|
|
|
let(:errors) { double(add: nil) }
|
|
|
|
|
|
|
|
before do
|
2023-02-20 01:32:10 +00:00
|
|
|
allow(user).to receive(:valid_invitation?).and_return(false)
|
2021-04-17 01:14:25 +00:00
|
|
|
allow_any_instance_of(described_class).to receive(:blocked_email_provider?) { blocked_email }
|
2018-12-29 06:23:44 +00:00
|
|
|
end
|
|
|
|
|
2021-04-17 01:14:25 +00:00
|
|
|
subject { described_class.new.validate(user); errors }
|
|
|
|
|
|
|
|
context 'when e-mail provider is blocked' do
|
2018-12-29 06:23:44 +00:00
|
|
|
let(:blocked_email) { true }
|
|
|
|
|
2021-04-17 01:14:25 +00:00
|
|
|
it 'adds error' do
|
|
|
|
expect(subject).to have_received(:add).with(:email, :blocked)
|
2018-12-29 06:23:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-17 01:14:25 +00:00
|
|
|
context 'when e-mail provider is not blocked' do
|
2018-12-29 06:23:44 +00:00
|
|
|
let(:blocked_email) { false }
|
|
|
|
|
2021-04-17 01:14:25 +00:00
|
|
|
it 'does not add errors' do
|
2023-02-20 01:33:27 +00:00
|
|
|
expect(subject).to_not have_received(:add).with(:email, :blocked)
|
2021-04-17 01:14:25 +00:00
|
|
|
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
|
|
|
|
expect(subject).to have_received(:add).with(:email, :taken)
|
|
|
|
end
|
2018-12-29 06:23:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|