Improve `SecurePasswordTest#test_authenticate`

- Ensure that execution of `authenticate`/`authenticate_XXX` returns
`self` if password is correct, otherwise `false` (as mentioned in the documentation).
- Test `authenticate_password`.
This commit is contained in:
bogdanvlviv 2018-07-06 20:21:58 +03:00
parent 73a9f64091
commit 382b5ca7dd
No known key found for this signature in database
GPG Key ID: E4ACD76A6DB6DFDD
1 changed files with 7 additions and 4 deletions

View File

@ -188,11 +188,14 @@ class SecurePasswordTest < ActiveModel::TestCase
@user.password = "secret"
@user.activation_token = "new_token"
assert_not @user.authenticate("wrong")
assert @user.authenticate("secret")
assert_equal false, @user.authenticate("wrong")
assert_equal @user, @user.authenticate("secret")
assert !@user.authenticate_activation_token("wrong")
assert @user.authenticate_activation_token("new_token")
assert_equal false, @user.authenticate_password("wrong")
assert_equal @user, @user.authenticate_password("secret")
assert_equal false, @user.authenticate_activation_token("wrong")
assert_equal @user, @user.authenticate_activation_token("new_token")
end
test "Password digest cost defaults to bcrypt default cost when min_cost is false" do