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