Skip to content

Commit cb56a1d

Browse files
yalabJonRowe
authored andcommitted
Support have_enqueued_mail matcher with a subclass of ActionMailer::DeliveryJob. (#2305)
1 parent 9e1f393 commit cb56a1d

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Bug Fixes:
55

66
* Remove warning when calling `driven_by` in system specs. (Aubin Lorieux, #2302)
77
* Fix comparison of times for `#at` in job matchers. (Jon Rowe, Markus Doits, #2304)
8+
* Fix when using a mailer with `delivery_job` set to a sub class of `ActionMailer::DeliveryJob` (Atsushi Yoshida #2305)
89

910
### 4.0.0 / 2020-03-24
1011
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v3.9.1...v4.0.0)

lib/rspec/rails/matchers/have_enqueued_mail.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ def mail_job_message(job)
131131
end
132132

133133
def legacy_mail?(job)
134-
job[:job] == ActionMailer::DeliveryJob
134+
job[:job] <= ActionMailer::DeliveryJob
135135
end
136136

137137
def parameterized_mail?(job)
138-
RSpec::Rails::FeatureCheck.has_action_mailer_parameterized? && job[:job] == ActionMailer::Parameterized::DeliveryJob
138+
RSpec::Rails::FeatureCheck.has_action_mailer_parameterized? && job[:job] <= ActionMailer::Parameterized::DeliveryJob
139139
end
140140

141141
def unified_mail?(job)
142-
RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery? && job[:job] == ActionMailer::MailDeliveryJob
142+
RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery? && job[:job] <= ActionMailer::MailDeliveryJob
143143
end
144144
end
145145
# @api public

spec/rspec/rails/matchers/have_enqueued_mail_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ class UnifiedMailer < ActionMailer::Base
2121
def test_email; end
2222
def email_with_args(arg1, arg2); end
2323
end
24+
25+
class DeliveryJobSubClass < ActionMailer::DeliveryJob
26+
end
27+
28+
class UnifiedMailerWithDeliveryJobSubClass < ActionMailer::Base
29+
self.delivery_job = DeliveryJobSubClass
30+
31+
def test_email; end
32+
end
2433
end
2534
end
2635

@@ -397,6 +406,12 @@ def self.name; "NonMailerJob"; end
397406
a_hash_including(params: {'foo' => 'bar'}, args: [1, 2])
398407
)
399408
end
409+
410+
it "passes when using a mailer with `delivery_job` set to a sub class of `ActionMailer::DeliveryJob`" do
411+
expect {
412+
UnifiedMailerWithDeliveryJobSubClass.test_email.deliver_later
413+
}.to have_enqueued_mail(UnifiedMailerWithDeliveryJobSubClass, :test_email)
414+
end
400415
end
401416
end
402417
end

0 commit comments

Comments
 (0)