Skip to content
Browse files

Fix secure_password setter

  • Loading branch information...
1 parent 71bd509 commit 692b3b6b6a565a27b968db8027daabcc766cfede @oscardelben oscardelben committed
View
2 activemodel/lib/active_model/secure_password.rb
@@ -64,8 +64,8 @@ def authenticate(unencrypted_password)
# 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
6 activemodel/test/cases/secure_password_test.rb
@@ -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

0 comments on commit 692b3b6

Please sign in to comment.
Something went wrong with that request. Please try again.