Class: DatabaseCleaner::ActiveRecord::Transaction

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

Instance Attribute Summary

Attributes inherited from Base

#connection_hash

Instance Method Summary collapse

Methods inherited from Base

#connection_class, #db=, exclusion_condition, migration_table_name

Instance Method Details

#cleanObject



20
21
22
23
24
25
26
27
# File 'lib/database_cleaner/active_record/transaction.rb', line 20

def clean
  connection_class.connection_pool.connections.each do |connection|
    connection.lock.synchronize do
      next unless connection.open_transactions > 0
      connection.rollback_transaction
    end
  end
end

#startObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/database_cleaner/active_record/transaction.rb', line 6

def start
  connection = if ::ActiveRecord.version >= Gem::Version.new("7.2")
    connection_class.lease_connection
  else
    connection_class.connection
  end

  # Hack to make sure that the connection is properly set up before cleaning
  connection.transaction {}

  connection.begin_transaction joinable: false
end