Skip to content

Commit

Permalink
Support have_enqueued_mail matcher with a subclass of `ActionMailer…
Browse files Browse the repository at this point in the history
…::DeliveryJob`. (#2305)
  • Loading branch information
yalab authored and JonRowe committed Mar 31, 2020
1 parent 9e1f393 commit cb56a1d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lib/rspec/rails/matchers/have_enqueued_mail.rb
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/rspec/rails/matchers/have_enqueued_mail_spec.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit cb56a1d

Please sign in to comment.