views:

14

answers:

0

Background:
Test drivers for rails that can test AJAX functionality (e.g. Selenium, EnvJS, akephalos etc) don't support transactional fixtures. I'm using Machinist and looking to do Capybara testing so I need some way to clear the test database after each test. Truncating every table in the test database is really slow (this is what the database_cleaner gem does).

Question:
Would there be a way, at the start of each test, to track all the instances of model objects created during the test and store them in an array, then during teardown go through the array in reverse order (so there won't be any dependency issues) and just delete the objects that were created during that specific test? This would be much faster than truncating every table in the database. Perhaps there is already some plugin out there that does this? If not, what would be the best way to approach this? Extend ActiveRecord::Base? Implement some sort of listener?