1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix secure_password setter

This commit is contained in:
Oscar Del Ben 2012-04-24 19:16:01 +02:00
parent 71bd5096be
commit 692b3b6b6a
2 changed files with 7 additions and 1 deletions

View file

@ -64,8 +64,8 @@ module ActiveModel
# Encrypts the password into the password_digest attribute.
def password=(unencrypted_password)
@password = unencrypted_password
unless unencrypted_password.blank?
@password = unencrypted_password
self.password_digest = BCrypt::Password.create(unencrypted_password)
end
end

View file

@ -19,6 +19,12 @@ class SecurePasswordTest < ActiveModel::TestCase
assert !@user.valid?, 'user should be invalid'
end
test "blank password doesn't override previous password" do
@user.password = 'test'
@user.password = ''
assert_equal @user.password, 'test'
end
test "password must be present" do
assert !@user.valid?
assert_equal 1, @user.errors.size