Update 3: It seems like this is specific to fixtures in a .yml.erb - even if I have no templated code, it seems like fixtures in a yml.erb file doesn't get loaded. Having a plain .yml file works. This likely has nothing to do with devise per se.
Note: see Update 3 annotations for relevant changes
I need to generate Devise users in my rails app. I notice that clearing the database and loading the fixtures loads all other fixtures, except the Devise users (Update 3: which is in a .yml.erb file).
I have seen this other thread, but I tried all the options there and still doesn't seem to load the fixtures.
# ../fixtures/users.yml.erb
user1:
email: user1@mysite.com
name: user1
encrypted_password: <%= Devise.bcrypt(User, 'passw0rd!') %>
# also tried encrypted_password: User.new(password_salt: '$2a$10$PoBe1MvkoGJsjMVTEjKqge').send(:password_digest, 'somepassword')
admin: true
And from the console:
To clear the test db:
$ bundle exec rake db:schema:load RAILS_ENV=test
To load the fixtures into test db:
$ bundle exec rake db:fixtures:load RAILS_ENV=test
Run rails console in test (no users found, but other model fixtures, like App, are being loaded):
$ rails c test
Loading test environment (Rails 4.1.5)
irb(main):001:0> User.first
User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
=> nil
irb(main):002:0> App.first
App Load (0.1ms) SELECT "apps".* FROM "apps" ORDER BY "apps"."id" ASC LIMIT 1
=> #<App id: 953336129,...>
Update 1: Also tried passing in encrypted password generated from console, still no user records are found:
admin:
email: user1@mysite.com
name: user1
encrypted_password: $2a$04$DR0.2yfWwD8AZlyeXx0gEuk2Qh.cNLF4cir0ZUB1iW7hwQhK/IfcC
admin: true
Update 2: It works when I rename fixtures file to users.yml. Renaming to users.yml.erb seems to be the culprit. BTW, the same behavior is seen (that is, it works with .yml, but not with yml.erb) on the console and from rake test