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

Perform email jobs in #assert_emails #32231

Merged

Conversation

@gmcgibbon
Copy link
Member

@gmcgibbon gmcgibbon commented Mar 12, 2018

Summary

Currently, ActionMailer's test helpers for asserting emails do not perform enqueued mail jobs. With this change, code like:

assert_emails(1) do
  perform_enqueud_jobs(only: ActionMailer::DeliveryJob) do
    SomeMailer.send_mail.deliver_later
  end
end

can be shortened to:

assert_emails(1) { SomeMailer.send_mail.deliver_later }

Are there any strong feelings against this change? What would be a scenario where this would not be wanted?

Perform enqueued delivery jobs in #assert_emails and #assert_no_emails.
@rails-bot
Copy link

@rails-bot rails-bot commented Mar 12, 2018

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@rafaelfranca rafaelfranca merged commit 96218b4 into rails:master Mar 13, 2018
2 checks passed
rafaelfranca added a commit that referenced this issue Mar 13, 2018
…_emails

Perform email jobs in #assert_emails
bogdanvlviv added a commit to bogdanvlviv/rails that referenced this issue Mar 13, 2018
- Remove extra execution of `perform_enqueued_jobs`
  since it performs all enqueued jobs in the duration of the block.
- Fix example of using `assert_emails` without block since we
  can't use enqueued jobs in this case.
kaspth added a commit that referenced this issue Mar 15, 2018
@gmcgibbon gmcgibbon deleted the perform_email_jobs_in_assert_emails branch Sep 18, 2018
@DylanReile
Copy link
Contributor

@DylanReile DylanReile commented Sep 4, 2019

Hey, @gmcgibbon, do you know what commit made this change necessary? Rails 5 pushes to ActionMailer::Base.deliveries without this.

@gmcgibbon
Copy link
Member Author

@gmcgibbon gmcgibbon commented Sep 4, 2019

@DylanReile That's probably related to the queue adapter you have configured for your app's test environment. The default one (async) doesn't performa jobs right away.

@DylanReile
Copy link
Contributor

@DylanReile DylanReile commented Sep 5, 2019

@gmcgibbon We're on config.active_job.queue_adapter = :test which I believe is the default since Rails 5. It works in Rails 5, but fails in Rails 6 without perform_enqueued_jobs. I was just curious about what happened in the interim.

@gmcgibbon
Copy link
Member Author

@gmcgibbon gmcgibbon commented Sep 5, 2019

We're on config.active_job.queue_adapter = :test which I believe is the default since Rails 5.

Generating a new app on Rails 5 and looking at the git history I don't see config.active_job.queue_adapter = :test ever being in test.rb by default. 🤔

@gaffneyc
Copy link

@gaffneyc gaffneyc commented Apr 1, 2020

Seems this is related to #37270 and the need for it was introduced by 96218b4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants