Fix bug when the reset_password_sent_at field doesn't exist generate_password_token returns nil causing the token not to be saved.

This commit is contained in:
Steve Hodgkiss
2011-04-17 22:59:30 +08:00
committed by José Valim
parent ee6a8ab93a
commit 60809719b8
2 changed files with 9 additions and 0 deletions

View File

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

View File

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