- Action Mailer delivery job should modify their `perform` method
signature in order to receive the new payload that Action Mailer
sends.
Before:
```ruby
def perform(mailer, mail_method, delivery_method, *args)
end
```
After:
```ruby
def perform(mailer, mail_method, delivery_method, args:)
end
```
This new behaviour was introduced couple years ago in a attempt to
get rid of the necessity to have a different job for paramterized
mailers. A deprecation was introduced for custom jobs inheriting
from `ActionMailer::DeliveryJob` but for jobs that didn't it went
unnoticed.
The deprecated behaviour was supposed to be removed in Rails 6.1
but we couldn't and it got reverted https://github.com/rails/rails/pull/39257
This reverts commit 0f9249c93f.
Reverted because this wasn't warning in custom jobs and therefore
applications may have not seen the deprecation. We'll need to fix the
deprecation to warn for custom jobs so that applications can migrate.
In the past, we sometimes hit missing `Symbol#start_with?` and
`Symbol#end_with?`.
63256bc5d7a8e812964d
So I proposed `Symbol#start_with?` and `Symbol#end_with?` to allow duck
typing that methods for String and Symbol, then now it is available in
Ruby 2.7.
https://bugs.ruby-lang.org/issues/16348
Using `String#starts_with?` and `String#ends_with?` could not be gained
that conveniency, so it is preferable to not use these in the future.
This hack prevails everywhere in the codebase by being copy & pasted, and it's actually not a negative thing but a necessary thing for framework implementors,
so it should better have a name and be a thing.
And with this commit, activesupport/test/abstract_unit.rb now doesn't silently autoload AS::TestCase,
so we're ready to establish clearner environment for running AS tests (probably in later commits)
This fixes the following warnings.
```
actionmailer/test/base_test.rb:272: warning: method redefined; discarding old welcome
actionmailer/test/base_test.rb:260: warning: previous definition of welcome was here
```
Without this change, `attachments.inline['my_attachment'].present?`, for example,
would raise the exception `Can't add attachments after mail was called`.
I first brought this issue up at https://github.com/rails/rails/issues/16163#issuecomment-437378347.
Note that this commit addresses only one of the 2 problems I described in that comment.
The other problem is that using `attachments.inline['my_attachment']` for reading an
attachment is unnecessary--it's the same as `attachments['my_attachment']`--even before
`mail` is called. We could add a warning about the unnecessary use of `inline` but I'm
saving that for a later PR since my comment has not received any feedback yet.
Previously this used self.formats= to set the format which render would
use to find templates. This worked, but was untested, and looked a
little confusing because it was doing the mutation within a loop.
This commit replaces the assignment with passing formats: [format] into
the render call, which makes it more obvious that that's the purpose of
the format. It also adds a test to verify the formats being used.
Since production applications typically run with log level info and
email adresses should be considered as sensitive data we want to prevent
them from ending up in the logs. In development mode (with log level
debug) they are still logged as part of the Mail::Message object.
- If a Mail defines a custom delivery_job, all ActionMailer assertion
helper (assert_emails, assert_enqueued_emails ...) wouldn't work.
```ruby
MyMailer < ApplicationMailer
self.delivery_job = MyJob
end
# This assertion will fail
assert_emails(1) do
MyMailer.my_mail.deliver_later
end
This PR leverage the new ActiveJob feature that accepts Procs for the
`only` keyword and check if the delivery job is one of ActionMailer
registered ones.
Up to `2.7.0`, encoding was chosen using `Mail::Encodings::TransferEncoding.negotiate`,
and base64 encoding was used.
In `2.7.1`, when `transfer_encoding` is not specified, the encoding
of the message is respected.
Related to: dead487e02
However, what chosen for transfer encoding is not essential in these tests.
To test more accurately, confirm that the decoded body instead.
Setting parameterized_delivery_job on a mailer class will cause Parameterized::MessageDelivery to use
the specified job instead of ActionMailer::Parameterized::DeliveryJob:
class MyMailer < ApplicationMailer
self.parameterized_delivery_job = MyCustomDeliveryJob
...
end