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

Introduce #deliver_enqueued_emails method to ActionMailer::TestHelper #47520

Conversation

andrewn617
Copy link
Contributor

@andrewn617 andrewn617 commented Feb 27, 2023

Motivation / Background

This Pull Request has been created because we have a deliver_enqueued_emails test helper method in the app I work on. I believe this method belongs within Rails and could be useful to anyone using the framework.

Detail

ActionMailer::TestHelper has an assert_enqueued_emails method, which just calls assert_enqueued_jobs with an only filter for mailer delivery jobs. By analogy, this PR introduces a deliver_enqueued_emails method, which calls perform_enqueued_jobs with a filter for delivery jobs.

Additional information

N/A

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rafaelfranca
Copy link
Member

Thanks. Can you write tests for this new helper?

@andrewn617
Copy link
Contributor Author

Ah sorry I missed that we have test helper tests. Yes I will add them.

@andrewn617 andrewn617 force-pushed the introduce-deliver-enqueued-emails-helper-method branch 3 times, most recently from 5d2c19f to a43ceab Compare February 28, 2023 14:53
end
end

assert_emails(1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you pass it a block, assert_emails delivers emails enqueued by the block. So to properly test this it needs to be called without a block.

@andrewn617
Copy link
Contributor Author

andrewn617 commented Feb 28, 2023

@rafaelfranca This is ready for another look.

…ethod delivers all enqueued email jobs.

Example:

```ruby
def test_deliver_enqueued_emails
  deliver_enqueued_emails do
    ContactMailer.welcome.deliver_later
    end
  assert_emails 1
end
```
@andrewn617 andrewn617 force-pushed the introduce-deliver-enqueued-emails-helper-method branch from a43ceab to f2cacd5 Compare February 28, 2023 19:10
rafaelfranca added a commit that referenced this pull request Feb 28, 2023
@rafaelfranca rafaelfranca merged commit f2cacd5 into rails:main Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants