How do I get rails to call db:seed before running my test suite? It appears that some task is being called that recreates the db, but doesn't call seed. Calling rake db:reset does both - it rebuilds the db and re-runs the seed scripts. How do I do this as part of rake test, or at the very least prevent test from resetting the db?
Asked
Active
Viewed 358 times
1 Answers
0
So I finally figured this out on my own (spent two days chasing). The db was being seeded from seeds.rb
, but I happened to have empty fixture yaml files for the tables I was looking at. Looking at this SO question gave me the idea to delete them, and voila - seed data abounds.
I won't accept this answer for a little while to give someone a chance to provide a better explanation, but thought I'd throw this out there.
-
in a rails test environment, the database gets reset each time a test is run. You should 'seed' the database for your tests with Factories using the FactoryGirl gem or something like it. – Andrew Sep 27 '14 at 02:20
-
@Andrew I have a bunch of reference data that needs to be there (lookup values and whatnot). It doesn't change, it's several hundred rows worth of data, and it needs to be correct. Doesn't seem to make sense to mock out. – kolosy Sep 27 '14 at 20:21
-
Maybe take a look at this answer then? http://stackoverflow.com/questions/1574797/how-to-load-dbseed-data-into-test-database-automatically – Andrew Sep 30 '14 at 20:56