test not rolling back

For testing, I use:

self.use_transactional_fixtures = true

This should cause a ROLLBACK for each test case. If I run a single file, foo_controller_test.rb, it works as expected. I see BEGIN and ROLLBACK 8 times in the log files. But if I run:

rake test:functionals

I get 3 COMMITs, 196 BEGINS and 193 ROLLBACKs. The code in fixtures.rb that deals with this is :

      def teardown_with_fixtures         return unless defined?(ActiveRecord::Base) && ! ActiveRecord::Base.configurations.blank?         # Rollback changes if a transaction is active.         if use_transactional_fixtures? && Thread.current['open_transactions'] != 0           ActiveRecord::Base.connection.rollback_db_transaction           Thread.current['open_transactions'] = 0         end         ActiveRecord::Base.verify_active_connections!       end

and I found that Thread.current['open_transactions'] equals zero in these cases.

anyone else encounter this or see something I'm missing? I guess I'll need to try to follow the increment/decrement of open_transactions.

This suggests that some of your code is committing transactions.

Fred

yea, I checked for that, and for creating Threads. Nothing.

Looking at the stacktrace of the call to commit, it appears active scaffold might have something to do with this. It's got it's own transaction wrapped around this. But it still seems like Thread.current['open_transactions'] should be 1 instead of zero in fixtures teardown. And certainly the result of running this via "rake test:functionals" should match the result running the file individually.

This was caused by having 2 controller testers with the same class name (cut/paste bug). Weird. I mean everything worked except the rollback of one test case. So whatever you do, don't do that.