In case of mail delivery errors, the old ActionMailer::LogSubscriber
erroneously logged a "Delivered mail ..." line.
With this change it checks the passed exception object and logs a
"Failed delivery of mail" line instead.
Co-authored-by: Christian Esser <c_esser@yahoo.de>
Fixes https://github.com/rails/rails/issues/48477
Using forms inside emails is not common, but it's possible, and it's also possible to share views between controllers and mailers. Currently if a controller sets a `default_form_builder` that's different from the global config, mailers that use the same views will not default to the same `FormBuilder`. To fix this, this PR adds a `default_form_builder` method for mailers that does the same thing as its controller sibling.
Since 6983a89c72 `require_dependency` is
obsolete since Rails stopped supporting classic mode.
It is only used by engines that need to support classic mode as well.
We can safely remove internal usage of `require_dependency`.
It was only used in the ActionMailer::Preview which is using just
`require` anyway.
Since this method has been documented in the guides for ages, it's probably safe.
https://guides.rubyonrails.org/testing.html#revenge-of-the-fixtures
TODO: I don't like how these methods are documented on
ActionMailer::TestCase::Behavior, even though the API is meant to be
exposed through ActionMailer::TestCase
Also add some additional words to make it clear that the modules also
implement handling the exceptions configured with rescue_from, because
it was not immediately clear that happened without reading the code.
In #45752, a `:params` kwarg was added to `assert_enqueued_email_with`
so that mailer params and args could be specified simultaneously.
However, for backward compatibility, the old behavior of treating an
`:args` Hash as params was preserved. The result is that if both
`:params` and `:args` are specified and `:args` is a Hash, `:params` is
ignored.
This commit deprecates specifying params via `:args` (i.e. passing a
Hash to `:args`).
After the deprecated behavior is removed, it will be possible to pass
a Hash to `:args`, and the Hash will be treated as named args instead.
Support args/params proc matchers in `assert_enqueued_email_with` to
make it behave more like `assert_enqueued_with`.
Fix#46621.
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
The `Type` class was introduced in https://github.com/rails/rails/pull/23085
for the sole purpose of breaking the dependency of Action View on Action Dispatch.
Unless you are somehow running Action View standalone, this is actually
never used.
So instead of delegating, we can use constant swapping, this saves us
a useless layer.
Ultimately we could consider moving `Mime::Types` into Active Support
but it requires some more thoughts.
Currently when opening the main framework pages there is no introduction
to the framework. Instead we only see a whole lot of modules and the
`gem_version` and `version` methods.
By including the READMEs using the `:include:` directive each frameworks
has a nice introduction.
For markdown READMEs we need to add the :markup: directive.
[ci-skip]
Co-authored-by: zzak <zzakscott@gmail.com>
* Remove Copyright years
* Basecamp is now 37signals... again
Co-authored-by: David Heinemeier Hansson <dhh@hey.com>
---------
Co-authored-by: David Heinemeier Hansson <dhh@hey.com>
The `deliver_later_queue_name` is already configurable on ActionMailer::Base,
however the value is inherited by all subclasses. Use a class-inheritable
attribute instead, so that subclasses can override.
Refs:
- https://github.com/rails/rails/pull/18587#issuecomment-324975192
Prior to this change, access to `params` on `ActionMailer::Base`
instances prior to being decorated by `ActionMailer::Parameterized.with`
calls results in a `NoMethodError`:
```
Error:
ParameterizedTest#test_degrade_gracefully_when_.with_is_not_called:
NoMethodError: undefined method `[]' for nil:NilClass
before_action { @inviter, @invitee = params[:inviter], params[:invitee] }
^^^^^^^^^^
```
This change modifies the `attr_accessor :params` to be an `attr_writer`
paired with a `params` method that assigns `@params` to an empty `Hash`
whenever it's accessed without being otherwise initialized.
This pattern is pretty common:
```ruby
assert_emails 1 do
post invite_user_path # ...
end
email = ActionMailer::Base.deliveries.last
assert_equal "You were invited!", email.subject
```
We can make it a bit nicer, by returning the email object from `assert_emails`. This is similar to how `assert_raises` returns the error so you can do additional checks on it. With this PR:
```ruby
email = assert_emails 1 do
post invite_user_path # ...
end
assert_equal "You were invited!", email.subject
```
If a single email is sent, a single `Mail::Message` is returned. If multiple emails were sent, an array is returned.
```ruby
emails = assert_emails 2 do
post invite_user_path # ...
end
emails.each do |email|
assert_equal "You were invited!", email.subject
end
```
The Mail gem changed format of the delivery method arguments for
sendmail from a string to an array of strings in this commit
7e1196bd29
As the settings are now a sendmail delivery method produces the
following error:
```
.../mail-2.8.0/lib/mail/network/delivery_methods/sendmail.rb:53:in `initialize': :arguments expected to be an Array of individual string args (ArgumentError)
```
This also updates the mail dependency since the new default won't work
with the older versions.
Since engine initializers run later in the process, we need to run this
initializer earlier than the default.
This ensures they're all registered before the environments are loaded.
This commit adds `ActionMailer.deprecator` and replaces all usages of
`ActiveSupport::Deprecation.warn` in `actionmailer/lib` with
`ActionMailer.deprecator`.
Additionally, this commit adds `ActionMailer.deprecator` to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.
The various LogSubscriber subclasses tend to subscribe to events
but then end up doing nothing if the log level is high enough.
But even if we end up not logging, we have to go through the
entire notification path, record timing etc.
By allowing subscribers to dynamically bail out early, we can
save a lot of work if all subscribers are silenced.
* This is an attempt to make the assert_enqueued_email_with easier to implement.
* Update actionmailer/test/test_helper_test.rb
Fix spelling.
* Documenting additional tests
* Missing a closing "end"
* Renaming tests for consistency
* Updating name
* Naming and documentation
* Leaving original test unchanged
* Fix test name, add new test
* Add assert_enqueued_emails examples to Rails guide
* Add example to test_helper
* Tweaking the Rails guide (#3)
* Updating Rails guide for consistency.
Co-authored-by: Bry <bryan.hunt@hey.com>
Co-authored-by: Ron Shinall <81988008+ron-shinall@users.noreply.github.com>