Merge pull request #5263 from tgxworld/improve_pattern

REFACTOR: Always validate email by default.
This commit is contained in:
Guo Xiang Tan 2017-10-26 14:34:09 +08:00 committed by GitHub
commit f1615c2148
4 changed files with 7 additions and 7 deletions

View File

@ -641,7 +641,7 @@ class UsersController < ApplicationController
primary_email = @user.primary_email primary_email = @user.primary_email
primary_email.email = params[:email] primary_email.email = params[:email]
primary_email.should_validate_email = true primary_email.skip_validate_email = false
if primary_email.save if primary_email.save
@user.email_tokens.create(email: @user.email) @user.email_tokens.create(email: @user.email)

View File

@ -89,7 +89,7 @@ class User < ActiveRecord::Base
after_initialize :add_trust_level after_initialize :add_trust_level
before_validation :set_should_validate_email before_validation :set_skip_validate_email
after_create :create_email_token after_create :create_email_token
after_create :create_user_stat after_create :create_user_stat
@ -1097,9 +1097,9 @@ class User < ActiveRecord::Base
true true
end end
def set_should_validate_email def set_skip_validate_email
if self.primary_email if self.primary_email
self.primary_email.should_validate_email = should_validate_email_address? self.primary_email.skip_validate_email = !should_validate_email_address?
end end
true true

View File

@ -3,7 +3,7 @@ require_dependency 'email_validator'
class UserEmail < ActiveRecord::Base class UserEmail < ActiveRecord::Base
belongs_to :user belongs_to :user
attr_accessor :should_validate_email attr_accessor :skip_validate_email
before_validation :strip_downcase_email before_validation :strip_downcase_email
@ -24,7 +24,7 @@ class UserEmail < ActiveRecord::Base
end end
def validate_email? def validate_email?
return false unless self.should_validate_email return false if self.skip_validate_email
email_changed? email_changed?
end end
end end

View File

@ -67,7 +67,7 @@ describe User do
end end
it "doesn't enqueue the system message when the site settings disable it" do it "doesn't enqueue the system message when the site settings disable it" do
SiteSetting.expects(:send_welcome_message?).returns(false) SiteSetting.send_welcome_message = false
Jobs.expects(:enqueue).with(:send_system_message, user_id: user.id, message_type: 'welcome_user').never Jobs.expects(:enqueue).with(:send_system_message, user_id: user.id, message_type: 'welcome_user').never
user.enqueue_welcome_message('welcome_user') user.enqueue_welcome_message('welcome_user')
end end