From 274f8f2f87d8033d0ad5da84ed397f76a23ba688 Mon Sep 17 00:00:00 2001 From: MatBi Date: Mon, 18 Apr 2016 19:35:56 +0800 Subject: [PATCH] Should send confirmation instructions after changing email from nil --- lib/devise/models/confirmable.rb | 4 ++-- test/models/confirmable_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb index 13533698..237ec67d 100644 --- a/lib/devise/models/confirmable.rb +++ b/lib/devise/models/confirmable.rb @@ -254,13 +254,13 @@ module Devise end def postpone_email_change? - postpone = self.class.reconfirmable && email_changed? && email_was.present? && !@bypass_confirmation_postpone && self.email.present? + postpone = self.class.reconfirmable && email_changed? && !@bypass_confirmation_postpone && self.email.present? @bypass_confirmation_postpone = false postpone end def reconfirmation_required? - self.class.reconfirmable && @reconfirmation_required && self.email.present? + self.class.reconfirmable && @reconfirmation_required && (self.email || self.unconfirmed_email) end def send_confirmation_notification? diff --git a/test/models/confirmable_test.rb b/test/models/confirmable_test.rb index 826e7bb7..5baf252e 100644 --- a/test/models/confirmable_test.rb +++ b/test/models/confirmable_test.rb @@ -401,6 +401,14 @@ class ReconfirmableTest < ActiveSupport::TestCase assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded end + test 'should send confirmation instructions by email after changing email from nil' do + admin = create_admin(email: nil) + assert_email_sent "new_test@example.com" do + assert admin.update_attributes(email: 'new_test@example.com') + end + assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded + end + test 'should not send confirmation by email after changing password' do admin = create_admin assert admin.confirm