Commit Graph

1742 Commits

Author SHA1 Message Date
Alex Ghiculescu 455e922b49
Introduce `capture_emails` and `capture_broadcasts` (#48798) 2023-07-25 06:42:54 +02:00
Alex Ghiculescu ba70a5be86 Make `perform_enqueued_jobs` compatible with all Active Job adapters 2023-06-28 20:08:08 +10: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 722d4f6582
Unlink Rails constant from READMEs 2023-05-29 15:14:44 +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
Shivam Chahar f30fc95c75 Remove redundant test 2023-05-22 19:31:46 +05:30
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
Shivam Chahar 88f9bc1237 Remove noise from actionmailer callbacks test 2023-04-26 21:38:54 +05:30
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
zzak b3d64e0112
🌶️ Spice up new Mailer preview for all headers 2023-02-09 14:50:47 +09:00
Guillermo Iguaran 6ba2e90bd3
Merge branch 'main' into matt/show-all-headers-email-preview 2023-02-08 11:03:25 -08:00
Matt Swanson 449d92dc2b Added option to show all headers for mailer previews 2023-02-08 11:00:51 -05:00
zzak f8544410a2 Use stable guides link for package READMEs
E.g.: These show up here:
https://api.rubyonrails.org/files/actioncable/README_md.html
2023-02-04 09:01:00 +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
Jonathan Hefner 48d4e6e02b Add ActionDispatch.deprecator
This commit adds `ActionDispatch.deprecator` and replaces all usages of
`ActiveSupport::Deprecation.warn` in `actionpack/lib/action_dispatch`
with `ActionDispatch.deprecator`.

Additionally, this commit adds `ActionDispatch.deprecator` to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.
2022-10-27 17:11:02 -05:00
Jean Boussier d917896f45 Enable verbose mode in test and report warnings as errors
We recently let a few very easy to avoid warnings get merged.
The root cause is that locally the test suite doesn't run in
verbose mode unless you explictly pass `-w`.

On CI warnings are enabled, but there is no reason to look at the
build output unless something is failing. And even if one wanted
to do that, that would be particularly work intensive since warnings
may be specific to a Ruby version etc.

Because of this I believe we should:

  - Always run the test suite with warnings enabled.
  - Raise an error if a warning is unexpected.

We've been using this pattern for a long time at Shopify both in private
and public repositories.
2022-10-11 09:25:18 +02:00
John Bampton 2f699c51ce Fix word case. `html` -> `HTML` 2022-09-18 04:21:22 +10:00
Yasuo Honda 349a66ebed Drop Rubinius code
Rubinius has not been maintained since May 2020 and based on the
discussion at https://github.com/rails/rails/pull/44984 ,
I think we can remove Rubinius specific code from Rails.
2022-09-15 23:43:51 +09: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
Jean Boussier fc0db35fb1 Add OutputBuffer#raw and #capture to reduce the need to swap the buffer
Right now many helpers have to deal with two modes of operation to
capture view output.

The main one is to swap the `@output_buffer` variable with a new buffer.
But since some view implementations such as `builder` keep a reference
on the buffer they were initialized with, this doesn't always work.

So additionally, the various capturing helpers also record the buffer
length prior to executing the block, and then `slice!` the buffer back
to its original size.

This is wasteful and make the code rather unclear.

Now that `OutputBuffer` is a delegator, I'd like to refactor all this
so that:

  - @output_buffer is no longer re-assigned
  - A single OutputBuffer instance is used for the entire response rendering
  - Instead capturing is done through `OutputBuffer#capture`

Once the above is achieved, it should allow us to enabled Erubi's
`:chain_appends` option and get some reduced template size and some
performance.

Not re-assigning `@output_buffer` will also allow template to access
the local variable instead of an instance variable, which is cheaper.

But more importantly, that should make the code easier to understand
and easier to be compatible with `StreamingBuffer`.
2022-08-03 12:56:34 +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