mirror of https://github.com/mastodon/mastodon
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
Ruby
52 lines
1.3 KiB
Ruby
6 years ago
|
# frozen_string_literal: true
|
||
|
|
||
|
require 'rails_helper'
|
||
|
|
||
5 months ago
|
RSpec.describe UserEmailValidator do
|
||
6 years ago
|
describe '#validate' do
|
||
11 months ago
|
subject { described_class.new.validate(user) }
|
||
2 years ago
|
|
||
2 years ago
|
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) }
|
||
6 years ago
|
|
||
|
before do
|
||
2 years ago
|
allow(user).to receive(:valid_invitation?).and_return(false)
|
||
2 years ago
|
allow(EmailDomainBlock).to receive(:block?) { blocked_email }
|
||
6 years ago
|
end
|
||
|
|
||
4 years ago
|
context 'when e-mail provider is blocked' do
|
||
6 years ago
|
let(:blocked_email) { true }
|
||
|
|
||
4 years ago
|
it 'adds error' do
|
||
11 months ago
|
subject
|
||
|
|
||
2 years ago
|
expect(errors).to have_received(:add).with(:email, :blocked).once
|
||
6 years ago
|
end
|
||
|
end
|
||
|
|
||
4 years ago
|
context 'when e-mail provider is not blocked' do
|
||
6 years ago
|
let(:blocked_email) { false }
|
||
|
|
||
4 years ago
|
it 'does not add errors' do
|
||
11 months ago
|
subject
|
||
|
|
||
2 years ago
|
expect(errors).to_not have_received(:add)
|
||
4 years ago
|
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
|
||
11 months ago
|
subject
|
||
|
|
||
2 years ago
|
expect(errors).to have_received(:add).with(:email, :taken).once
|
||
4 years ago
|
end
|
||
6 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|