Class: DatabaseCleaner::DataMapper::Transaction

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/database_cleaner/data_mapper/transaction.rb

Instance Method Summary collapse

Methods included from Base

#db, #db=

Methods included from Generic::Base

included

Instance Method Details

#clean(repository = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/database_cleaner/data_mapper/transaction.rb', line 16

def clean(repository = nil)
  repository = self.db if repository.nil?
  ::DataMapper.repository(repository) do |r|
    adapter = r.adapter
    while adapter.current_transaction
      adapter.current_transaction.rollback
      adapter.pop_transaction
    end
  end
end

#start(repository = nil) ⇒ Object

TODO Figure out repositories, may have to refactor connection_klass to something more sensible



7
8
9
10
11
12
13
14
# File 'lib/database_cleaner/data_mapper/transaction.rb', line 7

def start(repository = nil)
  repository = self.db if repository.nil?
  ::DataMapper.repository(repository) do |r|
    transaction = DataMapper::Transaction.new(r)
    transaction.begin
    r.adapter.push_transaction(transaction)
  end
end