Rails: devise validatable unit test always passes when it doesn't work

I'm missing something, but I can't seem to find the problem. This test is really simple and should fail, but it always passes. This creates a user with inappropriate passwords.

I have this in my user model. So I know: validatable is set.

devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable


When I test it manually using the console it works fine. This will prevent me from storing incorrect passwords.

Here is a unit test:

user = User.new_normal_user(
          :email                  => 'some@email.com', 
          :password               => 'some_password', 
          :password_confirmation  => 'some_other_password'

assert user.save


But for some strange reason when running a unit test, it saves when it shouldn't. I'm stumped. I cannot figure it out.


source to share

1 answer

I solved the problem. Did I overwrite password_required? function. Where it will only return under certain conditions. It will never come back. So I just returned true or false when needed, and the unit test works as expected and will catch passwords that don't match the problem.



All Articles