提交 692b3b6b 编写于 作者: O Oscar Del Ben

Fix secure_password setter

上级 71bd5096
...@@ -64,8 +64,8 @@ def authenticate(unencrypted_password) ...@@ -64,8 +64,8 @@ def authenticate(unencrypted_password)
# Encrypts the password into the password_digest attribute. # Encrypts the password into the password_digest attribute.
def password=(unencrypted_password) def password=(unencrypted_password)
@password = unencrypted_password
unless unencrypted_password.blank? unless unencrypted_password.blank?
@password = unencrypted_password
self.password_digest = BCrypt::Password.create(unencrypted_password) self.password_digest = BCrypt::Password.create(unencrypted_password)
end end
end end
......
...@@ -19,6 +19,12 @@ class SecurePasswordTest < ActiveModel::TestCase ...@@ -19,6 +19,12 @@ class SecurePasswordTest < ActiveModel::TestCase
assert !@user.valid?, 'user should be invalid' assert !@user.valid?, 'user should be invalid'
end 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 test "password must be present" do
assert !@user.valid? assert !@user.valid?
assert_equal 1, @user.errors.size assert_equal 1, @user.errors.size
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册