instance method
setup_transactional_fixtures
Ruby on Rails edge
Since v7.2.3.2 Private — implementation detail, not part of the public APISignature
setup_transactional_fixtures()
No documentation comment.
Source
# File activerecord/lib/active_record/test_fixtures.rb, line 192
def setup_transactional_fixtures
setup_shared_connection_pool
# Begin transactions for connections already established
pools = ActiveRecord::Base.connection_handler.connection_pool_list(:writing)
# Filter to pools that want to use transactions
pools.select! { |pool| transactional_tests_for_pool?(pool) }
# Record each pool as it is pinned. Teardown raises for a pool it is
# asked to unpin that never was, which buries whatever stopped it.
pools.each do |pool|
pool.pin_connection!(lock_threads)
@fixture_connection_pools << pool
pool.lease_connection
end
# When connections are established in the future, begin a transaction too
@connection_subscriber = ActiveSupport::Notifications.subscribe("!connection.active_record") do |_, _, _, _, payload|
connection_name = payload[:connection_name] if payload.key?(:connection_name)
shard = payload[:shard] if payload.key?(:shard)
if connection_name
pool = ActiveRecord::Base.connection_handler.retrieve_connection_pool(connection_name, shard: shard)
if pool
setup_shared_connection_pool
# Don't begin a transaction if we've already done so, or are not using them for this pool
if !@fixture_connection_pools.include?(pool) && transactional_tests_for_pool?(pool)
pool.pin_connection!(lock_threads)
@fixture_connection_pools << pool
pool.lease_connection
end
end
end
end
end
Defined in activerecord/lib/active_record/test_fixtures.rb line 192
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::TestFixtures