ActiveRecord currently wipes clean all data in the database before it starts testing. When using migrations to prefill data, you can't test that the prefilled data exists properly.
For example, I have a system that manages projects. The migration I set up prefills the Projects table with a project for the site. When I tried to write a unit test to verify that the migration worked properly, I found out that the prefilled data was removed. Part of that prefilled data was an image, so it won't fit well in YAML. And that's not the point--I shouldn't have to put that record in YAML in the first place. It's not an expected result.
I have a patch so that the Fixtures class in the ActiveRecord package will delete all records by ID for any given table. So if the YAML fixtures for my Project tests had 100 records starting with 100 and counting up to 199, only those records would be removed. Any records prefilled by the migrations would remain in tact--allowing me to write unit tests against it.
I'll submit the patch separately, but for now I will include it in line:
--- fixtures.rb 2006-02-22 22:31:27.890625000 -0500
+++ fixtures.rb.bak 2006-02-22 22:33:30.859375000 -0500
@@ -276,9 +276,7 @@
end
def delete_existing_fixtures
- values.each do |fixture|
- @connection.delete "DELETE FROM #{@table_name} WHERE ID=#{fixtureid?}", 'Fixture Delete'
- end
+ @connection.delete "DELETE FROM #{@table_name}", 'Fixture Delete'
end
def insert_fixtures