views:

15

answers:

1

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 standard than that of the legacy data.

A: 

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.

Steve Ross
I am running FactoryGirl on most of my tests, however, I am dealing with legacy data in my database that runs through filters when accessed. Thus, my real desire is to make sure my legacy conversion filters in my model are tested. As far as I have looked into factories, I have to pass everything through `create`, which creates a newer data standard than what I have in my existing database.
Levi McCallum
Can you clarify this? Is the database schema not the same as the Rails schema or are there data currently stored that would not pass validation? In short, what I'm wondering is how you are reading this data in.
Steve Ross