From 0ab28ef8eeb8c92442af7ab1689f87e4edde80af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 9 Mar 2012 18:12:30 +0100 Subject: [PATCH] Add skip_reconfirmation! , closes #1708 --- lib/devise/models/confirmable.rb | 8 +++++++- test/models/confirmable_test.rb | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb index 7bdfe6ed..41dea36f 100644 --- a/lib/devise/models/confirmable.rb +++ b/lib/devise/models/confirmable.rb @@ -54,7 +54,7 @@ module Devise self.confirmed_at = Time.now.utc if self.class.reconfirmable && unconfirmed_email.present? - @bypass_postpone = true + skip_reconfirmation! self.email = unconfirmed_email self.unconfirmed_email = nil @@ -108,6 +108,12 @@ module Devise self.confirmed_at = Time.now.utc end + # If you don't want reconfirmation to be sent, neither a code + # to be generated, call skip_reconfirmation! + def skip_reconfirmation! + @bypass_postpone = true + end + def headers_for(action) headers = super if action == :confirmation_instructions && pending_reconfirmation? diff --git a/test/models/confirmable_test.rb b/test/models/confirmable_test.rb index 2659ed4a..ae6ded5f 100644 --- a/test/models/confirmable_test.rb +++ b/test/models/confirmable_test.rb @@ -252,6 +252,15 @@ class ReconfirmableTest < ActiveSupport::TestCase assert_not_nil admin.confirmation_token end + test 'should not generate confirmation token if skipping reconfirmation after changing email' do + admin = create_admin + assert admin.confirm! + admin.skip_reconfirmation! + assert admin.update_attributes(:email => 'new_test@example.com') + assert_nil admin.confirmation_token + end + + test 'should regenerate confirmation token after changing email' do admin = create_admin assert admin.confirm!