Sha256: cf2ea4e21bc47100a9ae9695b1bf6a75a79ac60f5db6b3e781c5fb4c191d63af

Contents?: true

Size: 788 Bytes

Versions: 1

Compression:

Stored size: 788 Bytes

Contents

require 'database_cleaner/active_record/base'

module DatabaseCleaner
  module ActiveRecord
    class Transaction < Base
      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


      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
database_cleaner-active_record-2.2.0 lib/database_cleaner/active_record/transaction.rb