From b4794e041bb145b81edcfea0f6c3c1d05702124b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 14 Jul 2010 18:03:34 +0200 Subject: [PATCH] Save confirmation token to the database, if one does not exist but was requested, closes #377 --- lib/devise/models/confirmable.rb | 6 +++++- test/models/confirmable_test.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb index 446de099..aa2c4bc3 100644 --- a/lib/devise/models/confirmable.rb +++ b/lib/devise/models/confirmable.rb @@ -50,7 +50,7 @@ module Devise # Send confirmation instructions by email def send_confirmation_instructions - generate_confirmation_token if self.confirmation_token.nil? + generate_confirmation_token! if self.confirmation_token.nil? ::Devise.mailer.confirmation_instructions(self).deliver end @@ -127,6 +127,10 @@ module Devise self.confirmation_sent_at = Time.now.utc end + def generate_confirmation_token! + generate_confirmation_token && save(:validate => false) + end + module ClassMethods # Attempt to find a user by it's email. If a record is found, send new # confirmation instructions to it. If not user is found, returns a new user diff --git a/test/models/confirmable_test.rb b/test/models/confirmable_test.rb index ebff4edb..16890df8 100644 --- a/test/models/confirmable_test.rb +++ b/test/models/confirmable_test.rb @@ -133,7 +133,7 @@ class ConfirmableTest < ActiveSupport::TestCase user.instance_eval { def confirmation_required?; false end } user.save user.send_confirmation_instructions - assert_not_nil user.confirmation_token + assert_not_nil user.reload.confirmation_token end test 'should not resend email instructions if the user change his email' do