Load and use fixture in rails console

前端 未结 6 1808
南方客
南方客 2021-01-31 08:07

I wonder if there\'s a way to load and/or use fixture in rails console. Actually, I\'d like to create a user from my fixture users.yml to do some testing without ha

6条回答
  •  野的像风
    2021-01-31 09:00

    It's possible to specify an alternate fixture directory using the FIXTURES_DIR variable. The value should be relative to test/fixtures.

    $ rake db:fixtures:load RAILS_ENV=test FIXTURES_DIR='../../spec/fixtures'
    

    It's also possible to specify a limited set of fixtures

    $ rake db:fixtures:load RAILS_ENV=test FIXTURES_DIR='../../spec/fixtures' FIXTURES=users,user_roles
    

提交回复
热议问题