From 3b36479346daa334d2d5d89fbbdaf434af1a60d6 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Mon, 2 Sep 2024 15:57:57 +0100 Subject: [PATCH] Drop 6.1 related code --- lib/rspec/rails/fixture_support.rb | 3 +-- lib/rspec/rails/matchers/active_job.rb | 17 +++-------------- snippets/avoid_fixture_name_collision.rb | 3 --- ...clude_activesupport_testing_tagged_logger.rb | 7 +------ .../example/controller_example_group_spec.rb | 7 +------ 5 files changed, 6 insertions(+), 31 deletions(-) diff --git a/lib/rspec/rails/fixture_support.rb b/lib/rspec/rails/fixture_support.rb index b6727d71b..e56fabeb1 100644 --- a/lib/rspec/rails/fixture_support.rb +++ b/lib/rspec/rails/fixture_support.rb @@ -10,8 +10,7 @@ module FixtureSupport include ActiveRecord::TestFixtures # @private prevent ActiveSupport::TestFixtures to start a DB transaction. - # Monkey patched to avoid collisions with 'let(:name)' in Rails 6.1 and after - # and let(:method_name) before Rails 6.1. + # Monkey patched to avoid collisions with 'let(:name)' since Rails 6.1 def run_in_transaction? current_example_name = (RSpec.current_example && RSpec.current_example.metadata[:description]) use_transactional_tests && !self.class.uses_transaction?(current_example_name) diff --git a/lib/rspec/rails/matchers/active_job.rb b/lib/rspec/rails/matchers/active_job.rb index 583f56faf..40c676c0c 100644 --- a/lib/rspec/rails/matchers/active_job.rb +++ b/lib/rspec/rails/matchers/active_job.rb @@ -148,8 +148,8 @@ def base_job_message(job) msg_parts << "on queue #{job[:queue]}" if job[:queue] msg_parts << "at #{Time.at(job[:at])}" if job[:at] msg_parts << - if fetch_priority(job) - "with priority #{fetch_priority(job)}" + if job[:priority] + "with priority #{job[:priority]}" else "with no priority specified" end @@ -167,17 +167,6 @@ def job_matches?(job) @job ? @job == job[:job] : true end - # Rails 6.1 serializes the priority with a string key - if ::Rails.version.to_f >= 7 - def fetch_priority(job) - job[:priority] - end - else - def fetch_priority(job) - job['priority'] - end - end - def arguments_match?(job) if @args.any? args = serialize_and_deserialize_arguments(@args) @@ -218,7 +207,7 @@ def queue_match?(job) def priority_match?(job) return true unless @priority - @priority == fetch_priority(job) + @priority == job[:priority] end def at_match?(job) diff --git a/snippets/avoid_fixture_name_collision.rb b/snippets/avoid_fixture_name_collision.rb index 047d5c218..37f79003d 100644 --- a/snippets/avoid_fixture_name_collision.rb +++ b/snippets/avoid_fixture_name_collision.rb @@ -47,10 +47,7 @@ RSpec.describe 'Foo' do subject { true } - # Rails 6.1 and after let(:name) { raise "Should never raise" } - # Before Rails 6.1 - let(:method_name) { raise "Should never raise" } it { is_expected.to be_truthy } end diff --git a/snippets/include_activesupport_testing_tagged_logger.rb b/snippets/include_activesupport_testing_tagged_logger.rb index c8d87caf3..f3d446c5a 100644 --- a/snippets/include_activesupport_testing_tagged_logger.rb +++ b/snippets/include_activesupport_testing_tagged_logger.rb @@ -56,12 +56,7 @@ def perform describe 'error raised in perform_enqueued_jobs with block' do it 'raises the explicitly thrown error' do - # Rails 6.1+ wraps unexpected errors in tests - expected_error = if Rails::VERSION::STRING.to_f >= 6.1 - Minitest::UnexpectedError.new(TestError) - else - TestError - end + expected_error = Minitest::UnexpectedError.new(TestError) expect { perform_enqueued_jobs { TestJob.perform_later } } .to raise_error(expected_error) diff --git a/spec/rspec/rails/example/controller_example_group_spec.rb b/spec/rspec/rails/example/controller_example_group_spec.rb index fa524b0fc..d50e88ae5 100644 --- a/spec/rspec/rails/example/controller_example_group_spec.rb +++ b/spec/rspec/rails/example/controller_example_group_spec.rb @@ -54,12 +54,7 @@ def my_helper end end - # Rails 6.1 removes config from ./activerecord/lib/active_record/test_fixtures.rb - if respond_to?(:config) - config.include mod - else - ActiveRecord::Base.include mod - end + ActiveRecord::Base.include mod group.class_exec do let(:my_helper) { "my_value" }