Skip to content

Instantly share code, notes, and snippets.

@yclian
Created July 31, 2012 05:02
Show Gist options
  • Save yclian/3213816 to your computer and use it in GitHub Desktop.
Save yclian/3213816 to your computer and use it in GitHub Desktop.
RSpec helper that starts and rolls (back) a transaction
module DataMapperHelper
end
RSpec.configure do |c|
# See: http://rhnh.net/2010/10/06/transactional-before-all-with-rspec-and-datamapper
[:all, :each].each do |s|
c.before s, :type => :api do
repository :default do |r|
t = DataMapper::Transaction.new(repository)
t.begin
r.adapter.push_transaction(t)
end
end
c.after s, :type => :api do
repository(:default).adapter.pop_transaction.rollback
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment