Skip to content

Commit

Permalink
Moved from Rails.version check to ActiveRecord.version check (#987)
Browse files Browse the repository at this point in the history
  • Loading branch information
vimutter authored Jan 9, 2025
1 parent 09af153 commit a932e44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions lib/parallel_tests/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def load_lib
end

def purge_before_load
if Gem::Version.new(Rails.version) > Gem::Version.new('4.2.0')
if ActiveRecord.version > Gem::Version.new('4.2.0')
Rake::Task.task_defined?('db:purge') ? 'db:purge' : 'app:db:purge'
end
end
Expand Down Expand Up @@ -90,15 +90,15 @@ def parse_args(args)
end

def schema_format_based_on_rails_version
if rails_7_or_greater?
if active_record_7_or_greater?
ActiveRecord.schema_format
else
ActiveRecord::Base.schema_format
end
end

def schema_type_based_on_rails_version
if rails_61_or_greater? || schema_format_based_on_rails_version == :ruby
if active_record_61_or_greater? || schema_format_based_on_rails_version == :ruby
"schema"
else
"structure"
Expand Down Expand Up @@ -129,7 +129,7 @@ def build_run_command(type, args)
end

def configured_databases
return [] unless defined?(ActiveRecord) && rails_61_or_greater?
return [] unless defined?(ActiveRecord) && active_record_61_or_greater?

@@configured_databases ||= ActiveRecord::Tasks::DatabaseTasks.setup_initial_database_yaml
end
Expand All @@ -148,12 +148,12 @@ def for_each_database(&block)

private

def rails_7_or_greater?
Gem::Version.new(Rails.version) >= Gem::Version.new('7.0')
def active_record_7_or_greater?
ActiveRecord.version >= Gem::Version.new('7.0')
end

def rails_61_or_greater?
Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0')
def active_record_61_or_greater?
ActiveRecord.version >= Gem::Version.new('6.1.0')
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/parallel_tests/tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,19 @@ def call(command, grep)
end

describe ".purge_before_load" do
context 'Rails < 4.2.0' do
context 'ActiveRecord < 4.2.0' do
before do
stub_const('Rails', double(version: '3.2.1'))
stub_const('ActiveRecord', double(version: Gem::Version.new('3.2.1')))
end

it "should return nil for Rails < 4.2.0" do
it "should return nil for ActiveRecord < 4.2.0" do
expect(ParallelTests::Tasks.purge_before_load).to eq nil
end
end

context 'Rails > 4.2.0' do
context 'ActiveRecord > 4.2.0' do
before do
stub_const('Rails', double(version: '4.2.8'))
stub_const('ActiveRecord', double(version: Gem::Version.new('4.2.8')))
end

it "should return db:purge when defined" do
Expand Down

0 comments on commit a932e44

Please sign in to comment.