nested transactions
After an hour of head banging, well….banging our head trying to test that raising any error inside an ActiveRecord::Base#transaction block. It would appear that you can’t test a transaction in a test straight out the box. ActiveSupport::TestCase turns on transactional fixtures by default, in order that fixtures don’t get reloaded in every time a test is run. This makes sense and for this particular project there are silly amount of fixtures so this speeds up tests no end. However, this also means you can’t test a transaction inside a transaction because ActiveRecord doesn’t support nested transactions.
However, all is not lost you can turn off transactional fixtures on a test class by using the following.
self.use_transactional_fixtures = false
It’s a trade off on speed, so if you have a lot of tests it might be a better idea to move tests that rely on transactions working as they should into separate test classes.
Solution was found here: http://railspikes.com/2007/3/28/testing-transactions