Skip to content

Commit

Permalink
Fix secure_password setter
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardelben committed Apr 24, 2012
1 parent 71bd509 commit 692b3b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/secure_password.rb
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions activemodel/test/cases/secure_password_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 692b3b6

Please sign in to comment.