Skip to content

Commit

Permalink
Refine AR to enchant an ability to lease a connection when it cannot
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Jan 14, 2025
1 parent 88e04d2 commit 706e491
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/database_rewinder/cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

require_relative 'lease_connection_compat'
require_relative 'multiple_statements_executor'

using DatabaseRewinder::LeaseConnectionCompat
using DatabaseRewinder::MultipleStatementsExecutor

module DatabaseRewinder
Expand Down
14 changes: 14 additions & 0 deletions lib/database_rewinder/lease_connection_compat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module DatabaseRewinder
module LeaseConnectionCompat
# Make old AR compatible with AR >= 7.2 by defining `lease_connection`
unless ActiveRecord::ConnectionAdapters::ConnectionPool.instance_methods.include? :lease_connection
refine ActiveRecord::ConnectionAdapters::ConnectionPool do
def lease_connection
connection
end
end
end
end
end
3 changes: 3 additions & 0 deletions test/fake_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
ENV['DB'] ||= 'sqlite3'
require 'active_record/railtie'

require_relative '../lib/database_rewinder/lease_connection_compat'
using DatabaseRewinder::LeaseConnectionCompat

module DatabaseRewinderTestApp
Application = Class.new(Rails::Application) do
# Rais.root
Expand Down

0 comments on commit 706e491

Please sign in to comment.