Commit Graph

1119 Commits

Author SHA1 Message Date
Rafael Mendonça França
fb6c6007d0
Development of Rails 7.2 starts now
🎉
2023-09-27 03:59:11 +00:00
Rafael Mendonça França
e5386cb402
Preparing for 7.1.0.rc1 release 2023-09-27 03:08:31 +00:00
Christoph Geschwind
647e39b278
Log delivery errors in ActionMailer::LogSubscriber
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>
2023-09-27 02:45:55 +00:00
Alex Ghiculescu
9a2cf33f21
Introduce ActionMailer::FormBuilder
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.
2023-09-25 20:33:22 +00:00
Rafael Mendonça França
699dfdb426
Preparing for 7.1.0.beta1 release 2023-09-13 00:36:01 +00:00
Petrik
6998747947 Remove internal usage of require_dependency
Since 6983a89c726243fb38fe28cff49cba3a5f63ba6f `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.
2023-09-05 16:05:48 +02:00
Xavier Noria
b16adcd4e4 Generate config.autoload_lib(...) for new apps 2023-08-25 09:22:25 +02:00
Martin Spickermann
dd8b0e4684 Sort mailers on mailer preview page alphabetically 2023-08-21 11:11:25 +02:00
Alex Ghiculescu
455e922b49
Introduce capture_emails and capture_broadcasts (#48798) 2023-07-25 06:42:54 +02:00
zzak
dd89f600f7
🔗 Remove RDoc auto-link from Rails module everywhere 2023-06-23 10:49:30 +09:00
zzak
2cdb05f7e1
Make ActionMailer::TestCase#read_fixture public
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
2023-06-20 15:44:52 +09:00
zzak
38bef29064
Replace all occurrences of '<tt>(\w+::\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>Rails::Command::NotesCommand</tt> -> +Rails::Command::NotesCommand+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2023-05-25 06:56:17 +09:00
zzak
e3c73fd183
Replace all occurrences of '<tt>(\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>ActiveRecord::Base</tt> -> +ActiveRecord::Base+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-05-25 06:52:32 +09:00
Jonathan Hefner
fc9470aa97
Merge pull request #48194 from jonathanhefner/assert_enqueued_email_with-deprecate-params-via-args
Deprecate params via `:args` for `assert_enqueued_email_with`
2023-05-19 17:26:50 -05:00
Hartley McGuire
d028c14b03
Link rescue_from from modules including Rescuable
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.
2023-05-18 12:54:16 -04:00
Jonathan Hefner
19df946585 Deprecate params via :args for assert_enqueued_email_with
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.
2023-05-11 14:11:17 -05:00
Max Chernyak
96f19e965b Add matcher support to assert_enqueued_email_with
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>
2023-05-11 11:43:54 -05:00
Jean Boussier
06d2c2d15b Refactor ActionView::Template::Types to avoid delegation
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.
2023-05-08 10:34:46 +09:00
John Hawthorn
6cd8dddb92
Merge pull request #47630 from bensheldon/action_mailer_around_delivery
Add `*_deliver` callbacks for Action Mailer
2023-04-04 14:58:15 -07:00
Petrik
c09f5fa956 Add missing headers to Action Mailbox/Mailer/Text/View docs [ci-skip]
Having a h1 heading will improve SEO and makes things look more consistent.
2023-04-02 17:47:17 +02:00
Rafael Mendonça França
055572ec36
Correct documentation of assert_emails 2023-03-31 21:24:10 +00:00
Ben Sheldon
468d806406 Add *_deliver callbacks for Action Mailer 2023-03-29 17:12:19 -07:00
Petrik
7c94708d24 Include READMEs in main framework pages of the API documentation
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>
2023-03-21 21:16:28 +01:00
Rafael Mendonça França
0b95524ac8
Merge PR #47520 2023-02-28 19:13:45 +00:00
Rafael Mendonça França
c3a288b35b
Copy edits on latest patch 2023-02-28 19:13:31 +00:00
Andrew Novoselac
f2cacd5d11 Added deliver_enqueued_emails to ActionMailer::TestHelper. This method 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
```
2023-02-28 14:07:42 -05:00
Jeffrey Hardy
4d2eeafa70 Update Action Mailer's deliver_later_queue_name documentation with current defaults
Since Rails 6.1, the default configuration has been to use Active Job's default
queue, achieved by setting the queue name to `nil`.

Refs:
- https://github.com/rails/rails/pull/47408
- https://github.com/rails/rails/pull/47408#discussion_r1118672914
2023-02-27 12:42:14 -05:00
zzak
d2af670dba
Remove Copyright years (#47467)
* 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>
2023-02-23 11:38:16 +01:00
Jeffrey Hardy
fa17c9ac99 Allow mailer classes to customize the deliver_later queue name
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
2023-02-15 13:31:12 -05:00
Yasuo Honda
f838a74212
Merge pull request #46866 from ghousemohamed/change-year-2022-to-2023 2023-02-13 13:15:43 +09:00
Sean Doyle
6fea9a09f2 Gracefully degrade when ActionMailer::Base#params is nil
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.
2023-01-21 12:04:43 -05:00
Alex Ghiculescu
a3724cdd20 assert_emails: return the emails that were sent
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
```
2023-01-16 12:44:32 -07:00
Jonathan Hefner
cfe300ceb1 Format inline code [ci-skip] 2023-01-08 15:47:20 -06:00
Jonathan Hefner
3eadf057db Fix typos in API docs [ci-skip] 2023-01-08 15:47:20 -06:00
Ghouse Mohamed
e0559d2c1c Change 2022 -> 2023 2023-01-03 13:22:00 +05:30
Andy
0398459e9a Change sendmail default options to match Mail 2.8.x arguments format.
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.
2022-12-06 20:41:09 -05:00
Étienne Barrié
3d6a7b2faa Initialize deprecators before configuring them
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.
2022-11-28 10:47:26 +01:00
Jonathan Hefner
b3a2bb326c Add ActionMailer.deprecator
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`.
2022-10-29 16:01:02 -05:00
John Bampton
2f699c51ce Fix word case. html -> HTML 2022-09-18 04:21:22 +10:00
Igor Kasyanchuk
9f0a064fde
Added ability to download .eml file for the email preview. 2022-09-10 00:05:32 +03:00
Christian Schmidt
89fdd5e34e
Recommend mandatory STARTTLS for Google (#43594)
* Recommend mandatory STARTTLS

* Explain version constraints
2022-09-09 16:00:07 -04:00
Jean Boussier
bd19d1baf1 Optimize AS::LogSubscriber
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.
2022-08-12 09:58:17 +02:00
Rafael Mendonça França
95066e5fbd
Merge pull request #31595 from fatkodima/mailer-preview_paths
Support multiple preview paths for mailers
2022-08-09 16:20:18 -03:00
Tom Rossi
22a0692a59
Improvements to assert_enqueued_email_with (#45752)
* 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>
2022-08-09 14:16:19 +02:00
fatkodima
64ad045e47 Support multiple preview paths for mailers 2022-06-30 15:09:59 +03:00
Gannon McGibbon
0965560353 Improve mailer generator usage docs
- Makes heading styles consistent with other generators
- Adds backticks to code snippets
- Adds more examples
2022-06-21 00:30:27 -05:00
Jonathan Hefner
e4ec2cbb49
Merge pull request #44777 from jean-francois-labbe/main
Document action mailer rescue_from [ci-skip]
2022-05-03 10:47:38 -05:00
jean-francois labbe
f00151ab78 Document action mailer rescue_from
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-05-03 08:59:56 +02:00
Ryuta Kamizono
714fd07fd9 All intermediate delegation methods should preserve kwargs flag
Since 0456826180,
`foo(*caller_args)` method call delegation no longer preserve kwargs
flag.

Fixes #44846.
2022-04-06 15:32:54 +09:00
André Luis Leal Cardoso Junior
921263bb92 Only configure smtp_settings if provided on configuration 2022-03-15 22:31:04 -03:00