Skip to content

Commit

Permalink
Conditionalize for ActiveRecord 7.1+
Browse files Browse the repository at this point in the history
- Also remove old conditional
  • Loading branch information
joe-sharp committed Aug 7, 2024
1 parent c001b9c commit 15e1df5
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions spec/migration_lock_timeout/migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
require 'strong_migrations' if Gem.loaded_specs.has_key? 'strong_migrations'
require_relative '../../lib/migration-lock-timeout'

ACTIVE_RECORD_MIGRATION_CLASS = if ActiveRecord.gem_version < '5.0'
ActiveRecord::Migration
else
ActiveRecord::Migration[ActiveRecord::VERSION::STRING.to_f]
end
ACTIVE_RECORD_MIGRATION_CLASS = ActiveRecord::Migration[ActiveRecord::VERSION::STRING.to_f]

def expect_create_table
expect(ActiveRecord::Base.connection).to receive(:execute).
with('BEGIN', 'TRANSACTION').
if ActiveRecord.gem_version >= '7.1'
expect_any_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter).to receive(:execute).
with('BEGIN', 'TRANSACTION').
and_call_original
expect_any_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter).to receive(:execute).
with(/CREATE TABLE/).
and_call_original
expect(ActiveRecord::Base.connection).to receive(:execute).
with(/CREATE TABLE/).
and_call_original
else
expect(ActiveRecord::Base.connection).to receive(:execute).
with('BEGIN', 'TRANSACTION').
and_call_original
expect(ActiveRecord::Base.connection).to receive(:execute).
with(/CREATE TABLE/).
and_call_original
end
end

RSpec.describe ActiveRecord::Migration do

before { ActiveRecord::Base.logger = Logger.new(STDOUT) }
describe '#migrate' do

before(:each) do
Expand Down

0 comments on commit 15e1df5

Please sign in to comment.