mardi 27 février 2018

Ruby On Rails testing User Model with RSpec - password and password_confirmation doesn't work properly

it's my first post. I start to learn Ruby and Ruby On Rails framework.

I want to test User Model with RSpec and i have problem with pass validation of password and password_confirmation.

Code: https://github.com/paw3lgora/gCMS/blob/master/spec/models/user_spec.rb

I have problem with line: it { should validate_confirmation_of(:password) }

I don't wanna use devise gem or has_secure_password method from BCrypt because i learn Ruby and I want to implement my authentcation systems from scratch and add Argon2 in the future.

This give me error like:

1) User validation password should validate that :password_confirmation matches :password Failure/Error: it { should validate_confirmation_of(:password) }

   User did not properly validate that :password_confirmation matches
   :password.
     After setting :password_confirmation to ‹"some value"›, then setting
     :password to ‹"different value"›, the matcher expected the User to be
     invalid and to produce the validation error "doesn't match Password"
     on :password_confirmation. The record was indeed invalid, but it
     produced these validation errors instead:

     * name: ["Nazwa użytkownika nie może być pusta.", "Nazwa użytkownika
       jest za krótka. Minimum 2 znaki."]
     * email: ["Nie podałeś emaila.", "Email jest za krótki. Minimum 5
       znaków.", "Podałeś złą nazwę użytkownika."]
     * password_confirmation: ["Hasła nie pasują do siebie."]
 # ./spec/models/user_spec.rb:27:in `block (4 levels) in <top (required)>'

Help me guys! :)

Aucun commentaire:

Enregistrer un commentaire