mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 01:55:46 +08:00
Add BlockedEmail, to block signups based on email. Track stats of how many times each email address is blocked, and last time it was blocked. Move email validation out of User model and into EmailValidator. Signup form remembers which email addresses have failed and shows validation error on email field.
This commit is contained in:
23
spec/components/validators/email_validator_spec.rb
Normal file
23
spec/components/validators/email_validator_spec.rb
Normal file
@ -0,0 +1,23 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe EmailValidator do
|
||||
|
||||
let(:record) { Fabricate.build(:user, email: "bad@spamclub.com") }
|
||||
let(:validator) { described_class.new({attributes: :email}) }
|
||||
subject(:validate) { validator.validate_each(record,:email,record.email) }
|
||||
|
||||
context "blocked email" do
|
||||
it "doesn't add an error when email doesn't match a blocked email" do
|
||||
BlockedEmail.stubs(:should_block?).with(record.email).returns(false)
|
||||
validate
|
||||
record.errors[:email].should_not be_present
|
||||
end
|
||||
|
||||
it "adds an error when email matches a blocked email" do
|
||||
BlockedEmail.stubs(:should_block?).with(record.email).returns(true)
|
||||
validate
|
||||
record.errors[:email].should be_present
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user