From 60809719b8ad0ab8af7d8309e99daa3f93587ee5 Mon Sep 17 00:00:00 2001 From: Steve Hodgkiss Date: Sun, 17 Apr 2011 22:59:30 +0800 Subject: [PATCH] Fix bug when the reset_password_sent_at field doesn't exist generate_password_token returns nil causing the token not to be saved. --- lib/devise/models/recoverable.rb | 1 + test/models/recoverable_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/devise/models/recoverable.rb b/lib/devise/models/recoverable.rb index 7879a1dd..a4bb7a6a 100644 --- a/lib/devise/models/recoverable.rb +++ b/lib/devise/models/recoverable.rb @@ -73,6 +73,7 @@ module Devise def generate_reset_password_token self.reset_password_token = self.class.reset_password_token self.reset_password_sent_at = Time.now.utc if respond_to?(:reset_password_sent_at=) + self.reset_password_token end # Resets the reset password token with and save the record without diff --git a/test/models/recoverable_test.rb b/test/models/recoverable_test.rb index bb68caf7..dece471e 100644 --- a/test/models/recoverable_test.rb +++ b/test/models/recoverable_test.rb @@ -196,4 +196,12 @@ class RecoverableTest < ActiveSupport::TestCase end end + test 'should save the model when the reset_password_sent_at doesnt exist' do + user = create_user + user.stubs(:respond_to?).with(:reset_password_sent_at=).returns(false) + user.stubs(:respond_to?).with(:headers_for).returns(false) + user.send_reset_password_instructions + user.reload + assert_not_nil user.reset_password_token + end end