views:

17

answers:

1

I have some thinking-sphinx tests that I need to turn off transactions for to prevent mysql locks, but in doing so I break a lot of other tests previously written, so I need to be able to toggle the setting.

I have found similar questions regarding rspec, but none for Test::Unit.

I have tried self.use_transactional_fixtures = false which is what allows the sphinx tests to pass, but causes others to break. I am sure I could set that to true in all the other tests, but that would also require all other tests to include the code snippet as well which is messy.

I have also tried uses_transaction :test_method_name, but that works the same as the previously mentioned method.

Thanks in advance for any help.

+1  A: 

You should be able to set use_transactional_fixtures to false for just the sphinx related tests that you have, but leave it true for the other tests you have. The key will be to split your tests into separate test classes. So in test_helper.rb you'll still have:

self.use_transactional_fixtures = true

But then for your other tests you'll do something like

class PostTest < ActiveSupport::TestCase
  # your normal post tests that require transactional fixtures
end

class SphinxRelatedPostTest < ActiveSupport::TestCase
  self.use_transactional_fixtures = false
  # your other tests
end

That should mean that your regular tests run using the fast transactional fixtures, but rails will use the DELETE / INSERT method as required.

NZKoz
That is the way I have things setup, but with you saying the same thing I looked elsewhere for the problem. It turned out there was a few records in the delayed_jobs table that continually messed up count comparions. Thanks for the help.
chris