From defea6245c9ea66f30bdd311ac9a4d1b303abddf Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 25 Oct 2017 13:02:18 +0800 Subject: [PATCH] REFACTOR: Always validate email by default. --- app/controllers/users_controller.rb | 2 +- app/models/user.rb | 6 +++--- app/models/user_email.rb | 4 ++-- spec/models/user_spec.rb | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 346cf4d8bfe..be74190f803 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -641,7 +641,7 @@ class UsersController < ApplicationController primary_email = @user.primary_email primary_email.email = params[:email] - primary_email.should_validate_email = true + primary_email.skip_validate_email = false if primary_email.save @user.email_tokens.create(email: @user.email) diff --git a/app/models/user.rb b/app/models/user.rb index 2895c212321..522081371f2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -89,7 +89,7 @@ class User < ActiveRecord::Base 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_user_stat @@ -1097,9 +1097,9 @@ class User < ActiveRecord::Base true end - def set_should_validate_email + def set_skip_validate_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 true diff --git a/app/models/user_email.rb b/app/models/user_email.rb index c7b35eb3cea..2186e6522ee 100644 --- a/app/models/user_email.rb +++ b/app/models/user_email.rb @@ -3,7 +3,7 @@ require_dependency 'email_validator' class UserEmail < ActiveRecord::Base belongs_to :user - attr_accessor :should_validate_email + attr_accessor :skip_validate_email before_validation :strip_downcase_email @@ -24,7 +24,7 @@ class UserEmail < ActiveRecord::Base end def validate_email? - return false unless self.should_validate_email + return false if self.skip_validate_email email_changed? end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ee0b4405a2f..4f4071bffa0 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -67,7 +67,7 @@ describe User do end 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 user.enqueue_welcome_message('welcome_user') end