mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Merge pull request #2523 from Neschur/add_method_after_confrimation
Added method after_confrimation
This commit is contained in:
commit
78fedd6c10
2 changed files with 28 additions and 1 deletions
|
@ -66,7 +66,7 @@ module Devise
|
|||
self.confirmation_token = nil
|
||||
self.confirmed_at = Time.now.utc
|
||||
|
||||
if self.class.reconfirmable && unconfirmed_email.present?
|
||||
saved = if self.class.reconfirmable && unconfirmed_email.present?
|
||||
skip_reconfirmation!
|
||||
self.email = unconfirmed_email
|
||||
self.unconfirmed_email = nil
|
||||
|
@ -76,6 +76,9 @@ module Devise
|
|||
else
|
||||
save(:validate => false)
|
||||
end
|
||||
|
||||
after_confirmation if saved
|
||||
saved
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -264,6 +267,9 @@ module Devise
|
|||
confirmation_required? && !@skip_confirmation_notification && !self.email.blank?
|
||||
end
|
||||
|
||||
def after_confirmation
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Attempt to find a user by its email. If a record is found, send new
|
||||
# confirmation instructions to it. If not, try searching for a user by unconfirmed_email
|
||||
|
|
|
@ -312,6 +312,27 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|||
user.ensure_confirmation_token!
|
||||
assert_equal user.confirmation_token, old
|
||||
end
|
||||
|
||||
test 'should call after_confirmation if confirmed' do
|
||||
user = create_user
|
||||
user.define_singleton_method :after_confirmation do
|
||||
self.username = self.username.to_s + 'updated'
|
||||
end
|
||||
old = user.username
|
||||
assert user.confirm!
|
||||
assert_not_equal user.username, old
|
||||
end
|
||||
|
||||
test 'should not call after_confirmation if not confirmed' do
|
||||
user = create_user
|
||||
assert user.confirm!
|
||||
user.define_singleton_method :after_confirmation do
|
||||
self.username = self.username.to_s + 'updated'
|
||||
end
|
||||
old = user.username
|
||||
assert_not user.confirm!
|
||||
assert_equal user.username, old
|
||||
end
|
||||
end
|
||||
|
||||
class ReconfirmableTest < ActiveSupport::TestCase
|
||||
|
|
Loading…
Add table
Reference in a new issue