Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility with Rails 7.2 #165

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions lib/cypress-rails/manages_transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ def begin_transaction
@connections = gather_connections
@connections.each do |connection|
connection.begin_transaction joinable: false, _lazy: false
connection.pool.lock_thread = true
if connection.pool.respond_to?(:pin_connection!)
# Rails 7.2+
connection.pool.pin_connection!(true)
else
connection.pool.lock_thread = true
end
end

# When connections are established in the future, begin a transaction too
Expand All @@ -26,7 +31,12 @@ def begin_transaction

if connection && [email protected]?(connection)
connection.begin_transaction joinable: false, _lazy: false
connection.pool.lock_thread = true
if connection.pool.respond_to?(:pin_connection!)
# Rails 7.2+
connection.pool.pin_connection!(true)
else
connection.pool.lock_thread = true
end
@connections << connection
end
end
Expand All @@ -42,7 +52,12 @@ def rollback_transaction

@connections.each do |connection|
connection.rollback_transaction if connection.transaction_open?
connection.pool.lock_thread = false
if connection.pool.respond_to?(:unpin_connection!)
# Rails 7.2+
connection.pool.unpin_connection!
else
connection.pool.lock_thread = false
end
end
@connections.clear

Expand All @@ -58,7 +73,14 @@ def initialize
def gather_connections
setup_shared_connection_pool

ActiveRecord::Base.connection_handler.connection_pool_list.map(&:connection)
ActiveRecord::Base.connection_handler.connection_pool_list.map do |pool|
# Rails 7.2+
if pool.respond_to?(:lease_connection)
pool.lease_connection
else
pool.connection
end
end
end

# Shares the writing connection pool with connections on
Expand Down