Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix secure_password setter

  • Loading branch information...
commit f566d9cd3f501872ca2de3989cbdd99f02d7942f 1 parent b054789
Oscar Del Ben authored romanvbabenko committed
2  activemodel/lib/active_model/secure_password.rb
@@ -61,8 +61,8 @@ def authenticate(unencrypted_password)
61 61
       # Encrypts the password into the password_digest attribute, only if the
62 62
       # new password is not blank.
63 63
       def password=(unencrypted_password)
64  
-        @password = unencrypted_password
65 64
         unless unencrypted_password.blank?
  65
+          @password = unencrypted_password
66 66
           self.password_digest = BCrypt::Password.create(unencrypted_password)
67 67
         end
68 68
       end
6  activemodel/test/cases/secure_password_test.rb
@@ -19,6 +19,12 @@ class SecurePasswordTest < ActiveModel::TestCase
19 19
     assert !@user.valid?, 'user should be invalid'
20 20
   end
21 21
 
  22
+  test "blank password doesn't override previous password" do
  23
+    @user.password = 'test'
  24
+    @user.password = ''
  25
+    assert_equal @user.password, 'test'
  26
+  end
  27
+
22 28
   test "password must be present" do
23 29
     assert !@user.valid?
24 30
     assert_equal 1, @user.errors.size

0 notes on commit f566d9c

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