Skip to content

Instantly share code, notes, and snippets.

@beccasaurus
Created December 31, 2009 20:29
Show Gist options
  • Save beccasaurus/266898 to your computer and use it in GitHub Desktop.
Save beccasaurus/266898 to your computer and use it in GitHub Desktop.
Transactional specs with ActiveRecord (without Rails)
# ActiveRecord transactional specs (without Rails)
Spec::Runner.configure do |config|
config.before do
ActiveRecord::Base.connection.begin_db_transaction
ActiveRecord::Base.connection.increment_open_transactions
end
config.after do
if ActiveRecord::Base.connection.open_transactions != 0
ActiveRecord::Base.connection.rollback_db_transaction
ActiveRecord::Base.connection.decrement_open_transactions
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment