Related to this question: custom transaction doesn't work with database_cleaner in rspec
Is there any place one would not want to start a TX with requires_new? (which does nested TX)
ModelObject.transaction(requires_new: true)
If that's the case, should this have been the default.
BTW, this is a reason that an rspec test with a rollback will fail when the normal execution path of the code succeeds, when using the default transaction strategy.
Here's my DatabaseCleaner setup. Running Rails 4.
RSpec.configure do |config|
config.add_setting(:seed_tables)
config.seed_tables = %w(global_options shoot_types)
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation, except: config.seed_tables)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation, {except: config.seed_tables}
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html