Permalink
Browse files

Merge pull request #5966 from oscardelben/fix_secure_password_setter

Fix secure_password setter
  • Loading branch information...
2 parents f822024 + 692b3b6 commit 0cc32c5fd7f875de61262b430bca23825691899b @josevalim josevalim committed Apr 24, 2012
@@ -60,8 +60,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
@@ -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 0cc32c5

Please sign in to comment.