Class: DatabaseCleaner::ActiveRecord::Transaction
- Inherits:
-
Object
- Object
- DatabaseCleaner::ActiveRecord::Transaction
show all
- Includes:
- Base, Generic::Transaction
- Defined in:
- lib/database_cleaner/active_record/transaction.rb
Instance Attribute Summary
Attributes included from Base
#connection_hash
Instance Method Summary
collapse
#initialize
Methods included from Base
#connection_class, #db, #db=, #load_config, #valid_config
#cleaning, #db, included
Instance Method Details
#clean ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/database_cleaner/active_record/transaction.rb', line 29
def clean
connection_class.connection_pool.connections.each do |connection|
next unless connection.open_transactions > 0
if connection.respond_to?(:rollback_transaction)
connection.rollback_transaction
else
connection.rollback_db_transaction
end
if connection.respond_to?(:rollback_transaction_records, true)
connection.send(:rollback_transaction_records, true)
end
if connection_maintains_transaction_count?
if connection.respond_to?(:decrement_open_transactions)
connection.decrement_open_transactions
else
connection_class.__send__(:decrement_open_transactions)
end
end
end
end
|
#connection_maintains_transaction_count? ⇒ Boolean
54
55
56
|
# File 'lib/database_cleaner/active_record/transaction.rb', line 54
def connection_maintains_transaction_count?
ActiveRecord::VERSION::MAJOR < 4
end
|
#start ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/database_cleaner/active_record/transaction.rb', line 9
def start
connection_class.connection.transaction{ }
if connection_maintains_transaction_count?
if connection_class.connection.respond_to?(:increment_open_transactions)
connection_class.connection.increment_open_transactions
else
connection_class.__send__(:increment_open_transactions)
end
end
if connection_class.connection.respond_to?(:begin_transaction)
connection_class.connection.begin_transaction :joinable => false
else
connection_class.connection.begin_db_transaction
end
end
|