Reputation: 7866
I have just run into a situation where I had to tack down why my test user could not login in a system test.
It turns out that the password word for the user was nil.
I ran binding.pry after a user is created:
it 'some tests do
user = create(:user)
binding.pry
end
user.password = '12345' # correct
User.last.password = nil # wtf
user.email = '[email protected]' #correct
User.last.email = '[email protected]' #correct
Does anyone know why passwords are not persisted into the database with FactoryBot?
Upvotes: 0
Views: 518
Reputation: 2695
The reason User.last.password
is nil is because the plain text password is encrypted and not accessible. Check your schema.rb
file...you should only see an encrypted_password column (I'm assuming you are using Devise).
To check if the User is persisted just check user.persisted?
, user.errors
, or something of the sort to figure out whats going on.
Upvotes: 1