dimanche 23 avril 2017

How to reference user password in Rails testing fixture?

Surely this is asked and answered, but I cannot find an answer.

In rails, I have a typical setup with a users model. Passwords are not stored. Instead, I have a password_hash. I want to write a battery of tests for a controller, and that includes logging in. So I need to programmatically log in with typical login data, username and password. How do I store that in a fixture and then refer to it? Certainly I can create a fixture like

adam:
  username: 'adam'
  password_hash: '0e18f44c1fec03ec4083422cb58ba6a09ac4fb2a'

but that leaves me with no way to refer to the password programmatically---only to the password_hash. How does one do this typically?

Aucun commentaire:

Enregistrer un commentaire