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