I have a set of static records in my app that only need to be created once so I set up my test environment with:
RAILS_ENV=test rake db:test:prepare db:seed
Tests pass. Then later I add a new migration to my app. When I run tests again they start to fail because the static records that were created by
db:seed are missing.
The problem is that Rails doesn’t just call
db:migrate on the Test environment when there are new migrations. It instead calls
db:test:prepare without calling
db:seed. I think this happens here in
Based on the number of upvotes on the answers to this Stack Overflow question it looks a lot of people are working around this by either directly calling
Rails.application.load_seed from within their test code or they are configuring Rake to call
db:test:prepare should call
db:seed when it finishes?