Commit Graph

80 Commits

Author SHA1 Message Date
Jonathan Hefner
471ab2347f Omit workers and preload_app! from Puma config
Since Puma 5.0 (puma/puma@05936689c8),
Puma will automatically set `workers` to `ENV["WEB_CONCURRENCY"] || 0`.
Additionally, if `ENV["WEB_CONCURRENCY"]` > 1, Puma will automatically
set `preload_app`.

This can lead to confusing scenarios for users who are unaware of this
behavior and have customized `config/puma.rb`.  For example, if a user
uncomments the `workers` and `preload_app!` directives, it is clear that
Puma will preload the app, and the number of workers can be configured
by setting `ENV["WEB_CONCURRENCY"]`.  If the user sets
`ENV["WEB_CONCURRENCY"]` > 1, but then changes their mind and removes
the `workers` or `preload_app!` directives *without* clearing
`ENV["WEB_CONCURRENCY"]`, Puma will still preload the app and launch
`ENV["WEB_CONCURRENCY"]` number of workers.  Similarly, if a user
uncomments *only* the `workers` directive and sets
`ENV["WEB_CONCURRENCY"]` > 1, Puma will preload the app even though the
`preload_app!` directive is still commented out.

To avoid such scenarios, this commit removes the commented-out `workers`
and `preload_app!` directives from the default `config/puma.rb`.

Also, to improve discoverability of available configuration options,
this commit adds a link to the Puma DSL documentation at the top of the
file.
2022-06-03 12:38:21 -05:00
Dorian Marié
ebf916af2e Fixes development Action Mailbox new mail form
I wanted to add a test for sending an attachment that is an empty string
and a file but got this error:

NoMethodError: undefined method `original_filename' for "#<Rack::Test::UploadedFile:0x000000010840d388>":String

Related: #44702

Fixes #45088

-----

Started POST "/rails/conductor/action_mailbox/inbound_emails" for ::1 at 2022-05-14 07:34:19 +0200
Processing by Rails::Conductor::ActionMailbox::InboundEmailsController#create as HTML
  Parameters: {"authenticity_token"=>"[FILTERED]", "mail"=>{"from"=>"", "to"=>"", "cc"=>"", "bcc"=>"", "x_original_to"=>"", "in_reply_to"=>"", "subject"=>"", "body"=>"", "attachments"=>[""]}, "commit"=>"Deliver inbound email"}
Completed 500 Internal Server Error in 7ms (ActiveRecord: 0.0ms | Allocations: 2600)

NoMethodError (undefined method `original_filename' for "":String

            mail.add_file(filename: attachment.original_filename, content: attachment.read)
                                              ^^^^^^^^^^^^^^^^^^):

actionmailbox (7.0.3) app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb:26:in `block (2 levels) in new_mail'
actionmailbox (7.0.3) app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb:25:in `each'
actionmailbox (7.0.3) app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb:25:in `block in new_mail'
<internal:kernel>:90:in `tap'
actionmailbox (7.0.3) app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb:23:in `new_mail'
actionmailbox (7.0.3) app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb:17:in `create'

Co-Authored-By: Patrício dos Santos <hello@psantos.dev>
2022-05-15 22:59:48 +02:00
Xavier Noria
2953ae5c8a Define config.enable_reloading to be !config.cache_classes
Every time I write `config.cache_classes` I have to pause for a moment to make
sure I get it right. It makes you think.

On the other hand, if you read `config.enable_reloading = true`, does the
application reload? You do not need to spend 1 cycle of brain CPU to nod.
2022-04-14 18:11:36 +02:00
Lewis Buckley
246c13f8df
Change the AS::Notification payload to include the mailbox instance 2022-03-10 09:43:34 +00:00
Lewis Buckley
599e73bc00
Instrument Action Mailbox processing
Use ActiveSupport::Notifications to instrument Action Mailbox for
logging or performance monitoring.
2022-03-09 10:06:43 +00:00
Jonathan Hefner
4917ee9df6 Use dynamic Rails version in framework dummy apps
This matches what we currently generate for plugin dummy apps.
2021-12-08 11:31:49 -06:00
Rafael Mendonça França
83d85b2207
Start Rails 7.1 development 2021-12-07 15:52:30 +00:00
Alex Ghiculescu
5acc32ac54
Generate less initializers in new/upgraded Rails apps (part 2) (#43237) 2021-09-17 09:06:17 +02:00
Rafael Mendonça França
fd41ea1f2d
Merge branch 'main' into less-initializers 2021-09-15 17:18:49 -04:00
Xavier Noria
89801b2a43 Depend on ruby/debug, replacing Byebug
ruby/debug is a new debugger that is going to ship with CRuby.

It makes sense for Rails to switch to this one because that is
where the language is heading, and because Byebug is not fully
compatible with Zeitwerk. See

    https://github.com/deivid-rodriguez/byebug/issues/564

While ruby/debug has not been heavily tested with Zeitwerk,
casual usage seems to suggest it works without issues, including
explicit namespaces, which is where Byebug and Zeitwerk conflict.

Byebug is terrific, thanks a lot for all these years. ❤️
2021-09-08 17:35:41 +02:00
Koichi ITO
65af100ddd Tweak unreachable assertion tests in the block of assert_raises
I found an unexpected use of assertion in the block of `assert_raise`
when I implemented https://github.com/rubocop/rubocop-minitest/pull/137.
It is expected to be asserted after an exception is raised in
`assert_raise` block, but in actually it is not asserted after an
exception is raised. Therefore, this PR removes or updates assertions
that have not been asserted after an exception has raised.

This PR will add `rubocop-minitest` and enable
`Minitest/UnreachableAssertion` cop to able similar auto-detection,
but will remove `rubocop-minitest` from this PR if you don't like it.
2021-08-17 20:33:08 +09:00
David Heinemeier Hansson
e34300a921
Stop trying to configure listen by default on compatible platforms (#42985)
* Stop trying to configure listen by default on compatible platforms

Modern computers with SSDs don't see much/any benefit from having an evented file update watcher. Remove complexity by taking this spinning-drive concession out.

* Actually need listen for testing the opt-in

* Test no longer relevant
2021-08-11 15:18:43 +02:00
David Jones
c6c53a02a5 Permit attachments in mailbox conductor params
Prior to this commit, when adding attachments to an inbound email
through the conductor, the log would warn of an unpermitted parameter
with the message:

> Unpermitted parameter: :attachments. Context: { }

Also, if an application had the setting:

  config.action_controller.action_on_unpermitted_parameters = :raise

it would raise an error, because the attachments are not a permitted
parameter.

This commit also sets `action_on_unpermitted_parameters` to `:raise`
for the action mailbox test suite, so that tests are run in most
restrictive setting available, to prevent future unpermitted parameters
from being passed by conductor actions.

Co-authored-by: Dana Henke <danapalazzo1@gmail.com>
2021-07-02 16:56:16 -04:00
Yurii Rashkovskii
855e08d22d Problem: ActionMailbox uses default ActiveStorage service
This is imperfect in situations when a separation
between regular files (such as uploads) and emails
is necessary (for the purposes of regulatory compliance,
proper compartmentalization, etc.)

Solution: allow configuring ActionMailbox's storage service
2021-06-30 09:33:29 -07:00
Hartley McGuire
bcb300dccb Replace uglifier with terser in dummy applications
Terser is more up to date with modern javascript features, and the
uglifier gem repository recommends using it for minifying ES6+.

Followup for 955041b
2021-06-28 00:48:56 -04:00
Zachary Scott
c797ce966c Update test dummy application defaults
Affected gems:

* actionmailbox
* activestorage
* actiontext

This fixes the following warning:

DEPRECATION WARNING: Using legacy connection handling is deprecated. Please set
`legacy_connection_handling` to `false` in your application.

The new connection handling does not support `connection_handlers`
getter and setter.

Read more about how to migrate at: https://guides.rubyonrails.org/active_record_multiple_databases.html#migrate-to-the-new-connection-handling
 (called from require at ~/.gem/ruby/3.1.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34)
2021-06-21 07:00:32 +09:00
Alex Ghiculescu
de238125ef Generate less initializers in new/upgraded Rails apps
Currently when you make a new Rails app, we generate a lot of initializers. For new users, I think we should try and include as few as possible - the less files, the less daunting a new app is. And for upgrades I'd like to [continue to simplify the update process](https://github.com/rails/rails/pull/41083), in this case by not bringing back initializers you have probably already dismissed or modified.

In this PR I'm proposing we remove two initializers: `application_controller_renderer.rb` and `cookies_serializer.rb`:

**`application_controller_renderer.rb`**. This configures [`ActionController::Renderer`](https://api.rubyonrails.org/classes/ActionController/Renderer.html), for rendering views outside of controller actions. I don't think this is something most Rails apps will need (certainly not on day 1); users can configure this feature when they need it.

**`cookies_serializer.rb`**. This was added for [Rails 4.1](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#cookies-serializer). The behaviour is:

- For new apps, the initializer says `:json`.
- For upgraded apps that don't have the initializer, it is added with value `:marshal`.
- If there's no initializer, the [default value](c9a89a4067/actionpack/lib/action_dispatch/middleware/cookies.rb (L589)) is `:marshal`.

Since nobody should be upgrading direct from Rails 4.0 to Rails 7.0, we can simplify this by using new framework defaults. So the behavior will now be:

- For new apps, `config.load_defaults("7.0")` sets the value to `:json`.
- The `new_framework_defaults_7_0.rb` file explains this, and suggests using `:hybrid` to be upgrade to JSON cookies.
- No changes to [the code](c9a89a4067/actionpack/lib/action_dispatch/middleware/cookies.rb (L589)); the default value is `:marshal` if you don't set one.

So if you were not setting a `cookies_serializer` previously and you want to keep using `:marshal`, you'll need to explicitly set this before using `config.load_defaults("7.0")`, otherwise it will switch to `:json`. The upside of this is you won't get the `cookies_serializer.rb` file created for you every time you upgrade.
2021-06-18 16:13:05 -05:00
alkeshghorpade
c1eb749c3f Verify raised error message in test case 2021-06-01 21:00:13 +05:30
Henrik Nyh
515108ee03 'lookup' -> 'look up' in dummy webpacker.ymls
Corresponding to this fix: https://github.com/rails/webpacker/pull/2961
2021-03-21 12:36:56 +00:00
Christian Schmidt
6cd184ff0f
Use image/jpeg instead of non-standard image/jpg 2021-03-05 13:14:11 -05:00
George Claghorn
22f3dfe3cb
Upload raw email before creating pending ActionMailbox::InboundEmail
Fix that a storage upload error would leave behind a stuck-pending ActionMailbox::InboundEmail that could never be processed. The message isn't lost: the SMTP relay sees an HTTP server error and defers message delivery. We just have spurious, non-actionable InboundEmails stuck pending and tripping monitoring.

This does still leave behind an unattached ActiveStorage::Blob with no corresponding object on the storage service, but that's less annoying.
2021-01-04 09:28:09 -05:00
Alex Ghiculescu
76e432341c Always recommend config.asset_host in examples 2020-11-30 16:33:51 -06:00
Eugene Kenny
b7eaaf73fb Update comment about reloading in development.rb [ci skip]
This comment predates the existence of `reload_classes_only_on_change`.
2020-11-02 19:36:26 +00:00
Omri Gabay
43d83e96c9
Add option to mute multiple database yaml warning
Adds an option to silence the warning that database configurations can
throw when it's unparsable.
2020-10-29 16:57:57 -04:00
Jonathan Hefner
33fdae0584 Fix backtraces for generated plugin tests
`Minitest.plugin_rails_init` sets `Minitest.backtrace_filter` to
`Rails.backtrace_cleaner` right before tests are run, overwriting the
value set in test_helper.rb.

`Rails.backtrace_cleaner` silences backtrace lines that do not start
with `Rails.root` followed by e.g. "lib/" or "test/".  Thus when
`Rails.root` is a subdirectory of the project directory -- for example,
when testing a plugin that has a dummy app -- all lines of the backtrace
are silenced.

This commit adds a fallback such that when all backtrace lines are
silenced, the original `Minitest.backtrace_filter` is used instead.

Additionally, this commit refactors and expands existing test coverage.
2020-10-07 15:40:56 -05:00
bogdanvlviv
c15b5ab125
Eliminate fixture_file_upload related deprecation warnings in actionmailbox/test
https://buildkite.com/rails/rails/builds/71675#2b9c36e5-5504-4a8e-8c4d-af774e96ea16/954-982
https://buildkite.com/rails/rails/builds/71675#2b9c36e5-5504-4a8e-8c4d-af774e96ea16/954-988

```bash
.................DEPRECATION WARNING: Passing a path to `fixture_file_upload`
relative to `fixture_path` is deprecated.
In Rails 6.2, the path needs to be relative to `file_fixture_path`.

Please modify the call from
`fixture_file_upload("files/avatar1.jpeg")` to `fixture_file_upload("avatar1.jpeg")`.
DEPRECATION WARNING: Passing a path to `fixture_file_upload` relative to `fixture_path` is deprecated.
In Rails 6.2, the path needs to be relative to `file_fixture_path`.

Please modify the call from
`fixture_file_upload("files/avatar2.jpeg")` to `fixture_file_upload("avatar2.jpeg")`.
........................................................................
```

`fixture_file_upload` now uses path relative to `file_fixture_path`, see
https://github.com/rails/rails/pull/39086,
61c4be4777/actionmailbox/test/test_helper.rb (L21)
2020-09-21 16:14:20 +03:00
Akira Matsuda
47f5459138 Module#const_set is a public method 2020-09-15 17:19:37 +09:00
Mark Haussmann
71c8a89edd
Sendgrid: prepend X-Original-To header with envelope recipients
Sendgrid, like Mailgun, only passes BCC recipients as a parameter in the original JSON payload.

This PR adds code to prepend the recipients from the Sendgrid payload to the raw_email under the X-Original-To header.

References #38738.
2020-07-21 19:38:38 -04:00
fatkodima
6c4f3be929 Unify raise_on_missing_translations for views and controllers 2020-05-20 02:42:59 +03:00
Prathamesh Sonpatki
a673ce69e7
Rename annotate_template_file_names to annotate_rendered_view_with_filenames
- Add the configuration option for annotating templates with file names to the generated app.
- Add `annotate_rendered_view_with_filenames` option to configuring guide.
2020-05-19 09:28:14 +05:30
Bill Cromie
fce29be335 Add a route to handle Mandrill's webhook URL check
Mandrill's Inbound API checks to see if a URL exists before it creates
the webhook. It sends a HEAD request, to which we now return a 200 OK
response to indicate that the route exists.

Now we can generate inbound API calls with ease on Mandrill, without
having to shuffle around tokens in production.

Fixes #37609.
2020-04-07 13:22:36 +01:00
Joel Hawksley
a59e1de26a .annotate_template_file_names annotates HTML output with template file names
As a developer, when looking at a page in my web browser, it's sometimes
difficult to figure out which template(s) are being used to render the page.

config.action_view.annotate_template_file_names adds HTML comments to the
rendered output indicating where each template begins and ends.

Co-authored-by: Aaron Patterson <tenderlove@github.com>
2020-03-30 14:50:01 -06:00
David Heinemeier Hansson
3e0cdbeaf4
require, require_relative, load by double quotes (#38841)
* require, require_relative, load by double quotes

We're getting rid of all single quote usage, unless it serves a specific purpose, as per the general style guide.
2020-03-29 16:30:52 -07:00
Rikki Pitt
667d69cc5b
Add X-Original-To to mail using Mailgun recipient (#38738)
Expose the Mailgun SMTP recipient to Action Mailbox as X-Original-To, like Postfix.

Allows handling BCCed recipients who aren't listed in To/CC fields.
2020-03-23 18:10:48 -07:00
Matthijs Vos
8dca5162f9
Replace Mailgun API key with signing key
Mailgun now needs the signing key instead of the API key for validating incoming mails.
2020-02-21 11:33:04 -05:00
aminamos
65cbbf2282 implemented review feedback and the original change from parent PR in app_base.rb 2020-02-12 13:31:43 -05:00
aminamos
7bb0706f2c update from PR #36222 2020-02-12 13:31:43 -05:00
Haroon Ahmed
db1ae8cbb4 remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
Rafael Mendonça França
9e70042081
Merge pull request #28499 from grosser/grosser/puma
unify puma types and remove blocks
2019-12-18 10:23:08 -03:00
Eileen M. Uchitelle
cad13033fc
Merge pull request #37847 from pwim/action-mailbox-mail-ext-tests
Test extensions to Mail gem
2019-12-12 10:15:07 -05:00
George Claghorn
7d0327bbbf Track Active Storage variants in the database 2019-12-06 13:26:51 -05:00
Paul McMahon
40d63cee31 Test extensions to Mail gem
The from_address method is added to Mail::Message, but is not used
internally to ActionMailbox, nor tested (even implicitly). As it is part
of the public API, it feels important to at least have a basic test of
it.

Similarly, the x_original_to_addresses was only implicitly tested via
the recipients_addresses method. Given other similar methods are
explicitly tested, it feels like an oversight not to test it as well.

As the test introduced from_address didn't align with the naming of
RecipientsTest, I renamed it to the more generic AddressesTest.
2019-12-03 06:51:41 +09:00
DmitryTsepelev
e7f798c3f5 Allow configure services for individual attachments 2019-10-01 21:24:05 +03:00
Abhay Nikam
76ed911a91 Correct the assertion argument order 2019-08-08 00:06:34 +05:30
George Claghorn
c2f197c775 Correct assertion argument order 2019-08-07 10:54:56 -04:00
Michael Herold
ab34ed8acc Allow testing multipart emails in Action Mailbox
Allow passing a block to the create_inbound_email_from_mail and
receive_inbound_email_from_mail test helper methods.

When you wanted to test a multipart email -- for example, an email that
has both a plaintext part and an HTML part -- there wasn't a way to
easily build one without a pre-made fixture. By allowing you to pass a
block to these methods, we unlock the power of Mail.new to easily
create a variety of emails, from multi-part emails, to emails with
attachments, and beyond.
2019-08-07 10:12:13 -04:00
Akira Matsuda
0d981a2b3d Let the generated initializers/backtrace_silencers.rb code use Regexp#match? 2019-07-29 14:21:30 +09:00
John Duff
09e5d6d004 Fix Bcc header missing with emails from conductor and test helpers 2019-07-26 13:04:16 -04:00
George Claghorn
72bc0806a7 Correct assertion argument order 2019-07-25 22:34:40 -04:00
Kyle Keesling
ce88f6bd25
Fix filenames of attachments created via the inbound email conductor
controller passed along attachment file paths instead of their filenames
2019-07-25 21:11:29 -04:00