2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-07-25 13:01:27 -04:00
|
|
|
|
|
|
|
describe EmailValidator do
|
|
|
|
|
2016-07-04 10:05:01 -04:00
|
|
|
let(:record) { }
|
2013-07-25 13:01:27 -04:00
|
|
|
let(:validator) { described_class.new({attributes: :email}) }
|
|
|
|
subject(:validate) { validator.validate_each(record,:email,record.email) }
|
|
|
|
|
2015-06-14 21:28:50 -04:00
|
|
|
def blocks?(email)
|
|
|
|
user = Fabricate.build(:user, email: email)
|
|
|
|
validator = EmailValidator.new(attributes: :email)
|
|
|
|
validator.validate_each(user, :email, user.email)
|
|
|
|
user.errors[:email].present?
|
|
|
|
end
|
|
|
|
|
2013-07-25 13:01:27 -04:00
|
|
|
context "blocked email" do
|
|
|
|
it "doesn't add an error when email doesn't match a blocked email" do
|
2015-06-14 21:28:50 -04:00
|
|
|
expect(blocks?('sam@sam.com')).to eq(false)
|
2013-07-25 13:01:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "adds an error when email matches a blocked email" do
|
2015-06-14 21:28:50 -04:00
|
|
|
ScreenedEmail.create!(email: 'sam@sam.com', action_type: ScreenedEmail.actions[:block])
|
|
|
|
expect(blocks?('sam@sam.com')).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "blocks based on email_domains_blacklist" do
|
|
|
|
SiteSetting.email_domains_blacklist = "email.com|mail.com|e-mail.com"
|
2016-07-04 10:05:01 -04:00
|
|
|
expect(blocks?('sam@email.com')).to eq(true)
|
|
|
|
expect(blocks?('sam@bob.email.com')).to eq(true)
|
|
|
|
expect(blocks?('sam@e-mail.com')).to eq(true)
|
|
|
|
expect(blocks?('sam@googlemail.com')).to eq(false)
|
2013-07-25 13:01:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|