mirror of
https://github.com/jbranchaud/til
synced 2026-01-07 09:08:01 +00:00
Add Make ActionMailer Synchronous In Test as a rails til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
[til.hashrocket.com](https://til.hashrocket.com/).
|
||||||
|
|
||||||
_803 TILs and counting..._
|
_804 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -495,6 +495,7 @@ _803 TILs and counting..._
|
|||||||
- [Hash Slicing](rails/hash-slicing.md)
|
- [Hash Slicing](rails/hash-slicing.md)
|
||||||
- [Ignore Poltergeist JavaScript Errors](rails/ignore-poltergeist-javascript-errors.md)
|
- [Ignore Poltergeist JavaScript Errors](rails/ignore-poltergeist-javascript-errors.md)
|
||||||
- [List The Enqueued Jobs](rails/list-the-enqueued-jobs.md)
|
- [List The Enqueued Jobs](rails/list-the-enqueued-jobs.md)
|
||||||
|
- [Make ActionMailer Synchronous In Test](rails/make-action-mailer-synchronous-in-test.md)
|
||||||
- [Mark For Destruction](rails/mark-for-destruction.md)
|
- [Mark For Destruction](rails/mark-for-destruction.md)
|
||||||
- [Migrating Up Down Up](rails/migrating-up-down-up.md)
|
- [Migrating Up Down Up](rails/migrating-up-down-up.md)
|
||||||
- [Params Includes Submission Button Info](rails/params-includes-submission-button-info.md)
|
- [Params Includes Submission Button Info](rails/params-includes-submission-button-info.md)
|
||||||
|
|||||||
31
rails/make-action-mailer-synchronous-in-test.md
Normal file
31
rails/make-action-mailer-synchronous-in-test.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Make ActionMailer Synchronous In Test
|
||||||
|
|
||||||
|
When you set up an `ActionMailer` email, the default configuration is for it
|
||||||
|
to use `ActiveJob` to send the emails. [As of Rails 5, it will do so
|
||||||
|
asynchronously.](https://blog.bigbinary.com/2016/03/29/rails-5-changed-default-active-job-adapter-to-async.html).
|
||||||
|
Depending on your preferences for testing emails, you may prefer `ActiveJob`
|
||||||
|
to send the emails synchronously. This can be done by changing the
|
||||||
|
`queue_adapter` back to `:inline` in your `config/environments/test.rb`.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
config.active_job.queue_adapter = :inline
|
||||||
|
```
|
||||||
|
|
||||||
|
If you also configure the `delivery_method` as `:test`:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
config.action_mailer.delivery_method = :test
|
||||||
|
```
|
||||||
|
|
||||||
|
then emails will be queued up in `ActionMailer::Base.deliveries` allowing
|
||||||
|
you to write a test like this:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
expect(ActionMailer::Base.deliveries.count).to eq(1)
|
||||||
|
```
|
||||||
|
|
||||||
|
Check out [the
|
||||||
|
docs](https://guides.rubyonrails.org/action_mailer_basics.html) for more on
|
||||||
|
`ActionMailer`.
|
||||||
|
|
||||||
|
[source](https://stackoverflow.com/a/42987726/535590)
|
||||||
Reference in New Issue
Block a user