Skip to content

Commit

Permalink
Add compatibility for have_enqueued_mail (rails 7)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mhenrixon committed Nov 23, 2021
1 parent 1fe6c2e commit 3813e3d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/rspec/rails/feature_check.rb
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/rails/matchers/have_enqueued_mail.rb
Expand Up @@ -131,11 +131,11 @@ 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)
RSpec::Rails::FeatureCheck.has_action_mailer_parameterized? && job[:job] <= ActionMailer::Parameterized::DeliveryJob
RSpec::Rails::FeatureCheck.has_action_mailer_parameterized? && job[:job] <= base_mailer
end

def unified_mail?(job)
Expand Down
7 changes: 6 additions & 1 deletion spec/rspec/rails/matchers/have_enqueued_mail_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 3813e3d

Please sign in to comment.