After reading this
Rspec issue, I realized I can handle this as follows:
spec_helper.rb config.use_transactional_fixtures = true
config.before(:suite) do
DatabaseCleaner.strategy = :deletion # :truncation should work, :transaction doesn't work
end
Within a test block that needs transactions turned off to handle JavaScript:
before(:all) do # must be before
:all so transactions are disabled for entire block
self.use_transactional_fixtures = false
DatabaseCleaner.start
end
after(:each) do # still deletes records after each test
DatabaseCleaner.clean
self.use_transactional_fixtures = true
end
And if the test block needs to load data once for the whole block:
before(:all) do
self.use_transactional_fixtures = false
DatabaseCleaner.start
# Create data here (FactoryGirl.create...)
end
after(:all) do # Use after
:all so data stays around until the end of the block
DatabaseCleaner.clean
self.use_transactional_fixtures = true
end
Seems a little tricky (fragile?) to get all these bits working together...
Mark