Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 Rake Clone Database for Testing Environment

Is there a rake command in Rails 3 to clone my development database data? I noticed rake db:test:prepare and rake db:test:clone are mentioned throughout various blogs, but running them seems to do nothing. Furthermore, rake -T shows no db:test cases. I've resorted to loading a sql dump for now, but it would be great if I could just clone my existing development data for up-to-date testing.

EDIT -- I desire to test on a database since I am dealing with legacy data that I run through model filters when accessed. Factories won't work for me in this context, since data passed through create is defined as a different schema than that of the legacy data.

like image 912
Levi McCallum Avatar asked Oct 23 '10 05:10

Levi McCallum


2 Answers

rake db:test:prepare is still there even though it doesn't show up in rake -Tdb. I guess the Rails team decided to de-clutter the rake -T output?

like image 169
Aaron Gibralter Avatar answered Oct 27 '22 18:10

Aaron Gibralter


I would suggest you not clone your development database but rather rely on factories to give you predictable data you can craft for your exact test cases. Sooner or later, relying on having reliable test data in a database you can access will break your tests. It will also break the tests of anyone else who works on the project. And changes/additions to the data will not propagate to other developers as would your carefully constructed factories.

Look over Machinist, FixJour, FactoryGirl and the lot. They really solve the test data problem well and you check them into version control so the rest of your team has access to them.

like image 28
Steve Ross Avatar answered Oct 27 '22 17:10

Steve Ross