I have seeds.rb
populating my development database. And I know I can easily apply seeds.rb
to my test database using:
rake db:seed RAILS_ENV=test
However, I want a different seeds.rb
file to populate my test database. Maybe seeds_test.rb
. This must be an extremely common requirement among rails programmers, isn't it?
If there's no easy way to do this, like rake db:seed:seeds_test RAILS_ENV=test
, then how would I create a rake task? I would think something like this in lib/tasks/test_seeds.rake
:
namespace :db do
desc "Seed data for tests"
task :seed_test => :environment do
load "#{Rails.root}/db/seeds_test.rb"
end
end
I think that'll work, but then I would love for my rake task to automatically know to apply this only to the test database without me having to specify:
rake db:seed_test RAILS_ENV=test
How do I get the rake task so all I have to enter in the command line is:
rake db:seed_test
UPDATE: Another stackoverflow question was linked to where the answer was to do this:
Rails.env = 'test'
Unfortunately that doesn't actually do anything (at least as of Rails 4.2) :(.