Changes to email_domains_blacklist shouldn't invalidate existing users

This commit is contained in:
Neil Lalonde 2013-02-20 12:16:01 -05:00
parent a588f62fc7
commit 046c330858
2 changed files with 7 additions and 1 deletions

View file

@ -506,7 +506,7 @@ class User < ActiveRecord::Base
end
def email_validator
if (setting = SiteSetting.email_domains_blacklist).present?
if new_record? and (setting = SiteSetting.email_domains_blacklist).present?
domains = setting.gsub('.', '\.')
regexp = Regexp.new("@(#{domains})", true)
if self.email =~ regexp

View file

@ -478,6 +478,12 @@ describe User do
SiteSetting.stubs(:email_domains_blacklist).returns('trashmail.net')
Fabricate.build(:user, email: 'good@trashmailinet.com').should be_valid
end
it 'should not be used to validate existing records' do
u = Fabricate(:user, email: 'in_before_blacklisted@fakemail.com')
SiteSetting.stubs(:email_domains_blacklist).returns('fakemail.com')
u.should be_valid
end
end
describe 'passwords' do