2018-12-28 22:23:44 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-08-13 00:37:32 -07:00
|
|
|
RSpec.describe UserEmailValidator do
|
2018-12-28 22:23:44 -08:00
|
|
|
describe '#validate' do
|
2024-02-15 23:42:03 -08:00
|
|
|
subject { described_class.new.validate(user) }
|
2023-02-19 20:24:14 -08:00
|
|
|
|
2023-06-22 05:55:22 -07:00
|
|
|
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) }
|
2018-12-28 22:23:44 -08:00
|
|
|
|
|
|
|
before do
|
2023-02-19 17:32:10 -08:00
|
|
|
allow(user).to receive(:valid_invitation?).and_return(false)
|
2023-07-12 01:02:19 -07:00
|
|
|
allow(EmailDomainBlock).to receive(:block?) { blocked_email }
|
2018-12-28 22:23:44 -08:00
|
|
|
end
|
|
|
|
|
2021-04-16 18:14:25 -07:00
|
|
|
context 'when e-mail provider is blocked' do
|
2018-12-28 22:23:44 -08:00
|
|
|
let(:blocked_email) { true }
|
|
|
|
|
2021-04-16 18:14:25 -07:00
|
|
|
it 'adds error' do
|
2024-02-15 23:42:03 -08:00
|
|
|
subject
|
|
|
|
|
2023-07-12 01:02:19 -07:00
|
|
|
expect(errors).to have_received(:add).with(:email, :blocked).once
|
2018-12-28 22:23:44 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-16 18:14:25 -07:00
|
|
|
context 'when e-mail provider is not blocked' do
|
2018-12-28 22:23:44 -08:00
|
|
|
let(:blocked_email) { false }
|
|
|
|
|
2021-04-16 18:14:25 -07:00
|
|
|
it 'does not add errors' do
|
2024-02-15 23:42:03 -08:00
|
|
|
subject
|
|
|
|
|
2023-07-12 01:02:19 -07:00
|
|
|
expect(errors).to_not have_received(:add)
|
2021-04-16 18:14:25 -07: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
|
2024-02-15 23:42:03 -08:00
|
|
|
subject
|
|
|
|
|
2023-07-12 01:02:19 -07:00
|
|
|
expect(errors).to have_received(:add).with(:email, :taken).once
|
2021-04-16 18:14:25 -07:00
|
|
|
end
|
2018-12-28 22:23:44 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|