Add skip_reconfirmation! , closes #1708

This commit is contained in:
José Valim 2012-03-09 18:12:30 +01:00
parent b928b8b3a2
commit 0ab28ef8ee
2 changed files with 16 additions and 1 deletions

View File

@ -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?

View File

@ -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!