diff --git a/lib/active_record/pg_extensions/transaction.rb b/lib/active_record/pg_extensions/transaction.rb index aac3d02..1bb652d 100644 --- a/lib/active_record/pg_extensions/transaction.rb +++ b/lib/active_record/pg_extensions/transaction.rb @@ -17,7 +17,7 @@ def #{kind}(local: false) @#{kind} = timeout # If we have set an explicit timeout, the transaction has state that must be materialized # separately from any other transaction, so it cannot be `restartable` - dirty! unless ::Rails.version < '7.1' + dirty! return unless materialized? connection.set(#{kind.inspect}, "\#{(timeout * 1000).to_i}ms", local: true) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f71dcf0..58d35d4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,12 +27,7 @@ def executed_statements @executed_statements ||= [] end - methods = if Rails.version < "7.1" - %w[execute exec_no_cache exec_cache] - else - %w[internal_execute exec_no_cache exec_cache] - end - methods.each do |method| + %w[internal_execute exec_no_cache exec_cache].each do |method| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{method}(statement, *, **) materialize_transactions # this still needs to get called, even if we skip actually executing @@ -47,8 +42,7 @@ def #{method}(statement, *, **) # we can't actually generate a dummy one of these, so we just query the db with something # that won't return anything def empty_pg_result - conn = (::Rails.version < "7.1") ? @connection : @raw_connection - conn.async_exec("SELECT 0 WHERE FALSE") + @raw_connection.async_exec("SELECT 0 WHERE FALSE") end end ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(StatementCaptureConnection)