Skip to content

Commit

Permalink
Merge pull request #2523 from Neschur/add_method_after_confrimation
Browse files Browse the repository at this point in the history
Added method after_confrimation
  • Loading branch information
José Valim committed Jul 26, 2013
2 parents 14a0cfe + b7bc8de commit 78fedd6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/devise/models/confirmable.rb
Expand Up @@ -66,7 +66,7 @@ def confirm!
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
Expand All @@ -76,6 +76,9 @@ def confirm!
else
save(:validate => false)
end

after_confirmation if saved
saved
end
end

Expand Down Expand Up @@ -264,6 +267,9 @@ def send_confirmation_notification?
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
Expand Down
21 changes: 21 additions & 0 deletions test/models/confirmable_test.rb
Expand Up @@ -312,6 +312,27 @@ def confirm_user_by_token_with_confirmation_sent_at(confirmation_sent_at)
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
Expand Down

0 comments on commit 78fedd6

Please sign in to comment.