diff --git a/Changelog.md b/Changelog.md index 89b508d102..36f63ba610 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,7 @@ Bug Fixes: * Remove warning when calling `driven_by` in system specs. (Aubin Lorieux, #2302) * Fix comparison of times for `#at` in job matchers. (Jon Rowe, Markus Doits, #2304) +* Fix when using a mailer with `delivery_job` set to a sub class of `ActionMailer::DeliveryJob` (Atsushi Yoshida #2305) ### 4.0.0 / 2020-03-24 [Full Changelog](https://github.com/rspec/rspec-rails/compare/v3.9.1...v4.0.0) diff --git a/lib/rspec/rails/matchers/have_enqueued_mail.rb b/lib/rspec/rails/matchers/have_enqueued_mail.rb index bab5d0c425..b7756346e9 100644 --- a/lib/rspec/rails/matchers/have_enqueued_mail.rb +++ b/lib/rspec/rails/matchers/have_enqueued_mail.rb @@ -131,15 +131,15 @@ def mail_job_message(job) end def legacy_mail?(job) - job[:job] == ActionMailer::DeliveryJob + 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] <= ActionMailer::Parameterized::DeliveryJob end def unified_mail?(job) - RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery? && job[:job] == ActionMailer::MailDeliveryJob + RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery? && job[:job] <= ActionMailer::MailDeliveryJob end end # @api public diff --git a/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb index 2afdbbeeab..152e02fffc 100644 --- a/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb +++ b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb @@ -21,6 +21,15 @@ class UnifiedMailer < ActionMailer::Base def test_email; end def email_with_args(arg1, arg2); end end + + class DeliveryJobSubClass < ActionMailer::DeliveryJob + end + + class UnifiedMailerWithDeliveryJobSubClass < ActionMailer::Base + self.delivery_job = DeliveryJobSubClass + + def test_email; end + end end end @@ -397,6 +406,12 @@ def self.name; "NonMailerJob"; end a_hash_including(params: {'foo' => 'bar'}, args: [1, 2]) ) end + + it "passes when using a mailer with `delivery_job` set to a sub class of `ActionMailer::DeliveryJob`" do + expect { + UnifiedMailerWithDeliveryJobSubClass.test_email.deliver_later + }.to have_enqueued_mail(UnifiedMailerWithDeliveryJobSubClass, :test_email) + end end end end