[#4245] Allowing password to nil (#4261)

* [#4245] Allowing password to nil

* Set encrypted password to nil if password is nil

* [#4245] Fixing the build

* Removed unnecessary code
This commit is contained in:
sivagollapalli
2018-11-13 21:27:23 +05:30
committed by Leonardo Tegon
parent fa067b31c6
commit 3aedbf0a4d
2 changed files with 14 additions and 5 deletions

View File

@@ -117,9 +117,9 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
assert_nil user.authenticatable_salt
end
test 'should not generate a hashed password if password is blank' do
assert_blank new_user(password: nil).encrypted_password
assert_blank new_user(password: '').encrypted_password
test 'should set encrypted password to nil if password is nil' do
assert_nil new_user(password: nil).encrypted_password
assert_nil new_user(password: '').encrypted_password
end
test 'should hash password again if password has changed' do
@@ -307,4 +307,11 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
]
end
end
test 'nil password should be invalid if password is set to nil' do
user = User.create(email: "HEllO@example.com", password: "12345678")
user.password = nil
refute user.valid_password?('12345678')
refute user.valid_password?(nil)
end
end