From 495d8182b769a06b5389cf4b5e5cb82388839fb9 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Tue, 23 Nov 2021 20:59:48 +0100 Subject: [PATCH] Add compatibility for have_enqueued_mail (rails 7) 1. ActionMailer::DeliveryJob does not exist anymore 2. ActionMailer::Parameterized::DeliveryJob According to my research they have both been superseeded by ActionMailer::MailDeliveryJob Closes #2531 --- lib/rspec/rails/feature_check.rb | 6 +++++- lib/rspec/rails/matchers/have_enqueued_mail.rb | 2 +- spec/rspec/rails/matchers/have_enqueued_mail_spec.rb | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/rspec/rails/feature_check.rb b/lib/rspec/rails/feature_check.rb index 2570d6659b..4a4d855d75 100644 --- a/lib/rspec/rails/feature_check.rb +++ b/lib/rspec/rails/feature_check.rb @@ -28,13 +28,17 @@ def has_action_cable_testing? end def has_action_mailer_parameterized? - has_action_mailer? && defined?(::ActionMailer::Parameterized) + has_action_mailer? && defined?(::ActionMailer::Parameterized::DeliveryJob) end def has_action_mailer_unified_delivery? has_action_mailer? && defined?(::ActionMailer::MailDeliveryJob) end + def has_action_mailer_legacy_delivery_job? + defined?(ActionMailer::DeliveryJob) + end + def has_action_mailbox? defined?(::ActionMailbox) end diff --git a/lib/rspec/rails/matchers/have_enqueued_mail.rb b/lib/rspec/rails/matchers/have_enqueued_mail.rb index b7756346e9..36bf611aeb 100644 --- a/lib/rspec/rails/matchers/have_enqueued_mail.rb +++ b/lib/rspec/rails/matchers/have_enqueued_mail.rb @@ -131,7 +131,7 @@ def mail_job_message(job) end def legacy_mail?(job) - job[:job] <= ActionMailer::DeliveryJob + RSpec::Rails::FeatureCheck.has_action_mailer_legacy_delivery_job? && job[:job] <= ActionMailer::DeliveryJob end def parameterized_mail?(job) diff --git a/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb index 152e02fffc..0e3d4420cc 100644 --- a/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb +++ b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb @@ -22,7 +22,12 @@ def test_email; end def email_with_args(arg1, arg2); end end - class DeliveryJobSubClass < ActionMailer::DeliveryJob + if RSpec::Rails::FeatureCheck.has_action_mailer_legacy_delivery_job? + class DeliveryJobSubClass < ActionMailer::DeliveryJob + end + else + class DeliveryJobSubClass < ActionMailer::MailDeliveryJob + end end class UnifiedMailerWithDeliveryJobSubClass < ActionMailer::Base