diff --git a/lib/database_rewinder/cleaner.rb b/lib/database_rewinder/cleaner.rb index d25ad9e..4be5a5a 100644 --- a/lib/database_rewinder/cleaner.rb +++ b/lib/database_rewinder/cleaner.rb @@ -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 diff --git a/lib/database_rewinder/lease_connection_compat.rb b/lib/database_rewinder/lease_connection_compat.rb new file mode 100644 index 0000000..c812d99 --- /dev/null +++ b/lib/database_rewinder/lease_connection_compat.rb @@ -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 diff --git a/test/fake_app.rb b/test/fake_app.rb index 19af43d..a30ca79 100644 --- a/test/fake_app.rb +++ b/test/fake_app.rb @@ -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