Transactional Fixtures in Ruby on Rails

July 6, 2005

Since our move to PostgreSQL, I've run in to an odd issue. I use transactional fixtures to reduce the time it takes to run my tests. This works great, unless the test case actually uses ActiveRecord::Transactions. The nested transactions seem to be causing problems, so I needed a way to turn off transactional fixtures for that single test method. Here's what I found after some digging through ActiveRecord::Fixtures: class AccountControllerTest < Test::Unit::TestCase fixtures .... uses_transaction :test_should_not_use_transactional_fixtures def test_should_not_use_transactional_fixtures end end Apparently, the uses_transaction class method can specify one or more methods that don't use transactions. Still, it doesn't make sense, it seems like only those specified methods should be using transactional fixtures. I haven't seen any mention of this, so I just hope I'm using it correctly.