views:

147

answers:

2

I am in the process of upgrading my application to Rails 3. I started using Rspec 2 with Rails 3. I need to turn off transactional fixtures for some of my rspec tests. Prior I used the following code in my model specs

 before(:all) do
    ActiveSupport::TestCase.use_transactional_fixtures = false
  end

  after(:all) do
    ActiveSupport::TestCase.use_transactional_fixtures = true
    clean_engine_database
  end

That now gives me the error:

 Failure/Error: ActiveSupport::TestCase.use_transactional_fixtures = false
     undefined method `use_transactional_fixtures=' for ActiveSupport::TestCase:Class

Is there a way to do this per test block in Rails 3 with Rspec 2?

A: 

You can disable transactional fixtures globally by putting config.use_transactional_fixtures = false on the spec_helper.rb. If you want to control them by test (e.g. use transactional just on some of them), you can set this behavior with DatabaseCleaner.

I've had a related problem when testing pages with javascript on the browser (a scenario that does not work with transactional fixtures). Here's how I managed to work around it: http://github.com/lailsonbm/contact_manager_app

Lailson Bandeira
A: 
RSpec.configure do |config|
  config.use_transactional_fixtures = true
end
David Chelimsky
This didn't work. I put this in the before(:all) and it doesn't seem to work. I'm still getting this error which is typically solved by turning off transactional fixtures for the test.PGError: ERROR: SET TRANSACTION ISOLATION LEVEL must be called before any query
Nicolo77
You should put this code outside any `:all` or `describe` block. The spec_helper.rb file is a good place if you wanna set this globally. And I think David meant to say `false` instead of `true`.
Lailson Bandeira