Skip to content

Commit

Permalink
Add more tests (#4970)
Browse files Browse the repository at this point in the history
After merging #4261, I realized that we could add a couple more
tests, to ensure the new behavior added to `#valid_password?` - which is
that it should return `false` when the password is either `nil` or blank
('').
I've also removed [this
condition](https://github.com/plataformatec/devise/blob/master/lib/devise/models/database_authenticatable.rb#L68)
because it's already present at `Devise::Encryptor` module in the
`.compare`
[method](https://github.com/plataformatec/devise/blob/master/lib/devise/encryptor.rb#L15).
  • Loading branch information
tegon committed Nov 13, 2018
1 parent 40f02ae commit 05bf574
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/devise/models/database_authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def password=(new_password)

# Verifies whether a password (ie from sign in) is the user password.
def valid_password?(password)
return false if password.blank?
Devise::Encryptor.compare(self.class, encrypted_password, password)
end

Expand Down
10 changes: 10 additions & 0 deletions test/models/database_authenticatable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ def setup
refute user.valid_password?('654321')
end

test 'should be invalid if the password is nil' do
user = new_user(password: nil)
refute user.valid_password?(nil)
end

test 'should be invalid if the password is blank' do
user = new_user(password: '')
refute user.valid_password?('')
end

test 'should respond to current password' do
assert new_user.respond_to?(:current_password)
end
Expand Down

0 comments on commit 05bf574

Please sign in to comment.