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