How to create fixtures (for a Devise user) as a yml.erb in rails (4.1.5)?

You should pass the password in plain text too. I am sure there is a User model validation errors preventing your fixture users from being created. Here’s an example from my users fixture which works:

tom:
  first_name: Tom
  last_name: Test
  email: [email protected]
  password: 123greetings
  encrypted_password: <%= User.new.send(:password_digest, '123greetings') %>

If it still fails, please check the log/test.log file for errors and check for missing required fields or other validation rules you set in your User model.

Update:
It turns out that author found the issue himself – used .yml.erb file extension rather than .yml which made rails bypass that fixtures file. ERB works in yml fixtures as rails runs the fixture file through ERB before parsing it.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)