Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It supports have_enqueud_mail matcher sub class of DeliveryJob. #2305

Merged
merged 3 commits into from Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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