Commit Graph

14254 Commits

Author SHA1 Message Date
Jonathan Hefner 369afa63d0 Fix allow_deprecated_singular_associations_name framework default
Follow-up to #45344.

When using `config.load_default "7.1"`, the value is `false`, so the
value in `new_framework_defaults_7_1.rb` should be `false` as well.

This commit also adds configuration tests.
2022-06-23 14:53:27 -05:00
eileencodes 9766eb4a83
Fix tests for minitest 5.16
In minitest/minitest@6e06ac9 minitest changed such that it now accepts
`kwargs` instead of requiring kwargs to be shoved into the args array.
This is a good change but required some updates to our test code to get
the new version of minitest passing.

Changes are as follows:

1) Lock minitest to 5.15 for Ruby 2.7. We don't love this change but
it's pretty difficult to get 2.7 and 3.0 to play nicely together with
the new kwargs changes. Dropping 2.7 support isn't an option right
now for Rails. This is safe because all of the code changes here are
internal methods to Rails like assert_called_with. Applications
shouldn't be consuming them as they are no-doc'd.
2) Update the `assert_called_with` method to take any kwargs but also
the returns kwarg.
3) Update callers of `assert_called_with` to move the kwargs outside the
args array.
4) Update the message from marshaled exceptions. In 5.16 the exception
message is "result not reported" instead of "Wrapped undumpable
exception".

Co-authored-by: Matthew Draper <matthew@trebex.net>
2022-06-23 08:32:11 -04:00
Eugene Kenny 7669a4a975
Merge pull request #45404 from skipkayhil/rm-load-path-modification
Remove load path modification from Rails 3 days
2022-06-20 21:30:40 +01:00
Jonathan Hefner 5a5440ba72
Merge pull request #45402 from brtrick/bt/add-skip-dev-gems-as-class-option
Set `skip_dev_gems` to be a `class_option`
2022-06-20 14:20:28 -05:00
Hartley McGuire 27285e7881
Remove special handling for ActiveRecordStore
activerecord-session_store was removed in 0ffe190, and has been
displaying a special error message when missing since Rails 4.0.

Replace the specific error message so that third party stores get nicer
error handling as well
2022-06-20 00:35:36 -04:00
Hartley McGuire 253a6338ca
Remove load path modification from Rails 3 days
This seems to be a pattern that was common around Rails 3 (for example,
it was last changed in 7ee5843). However, most of the usages were
removed in 36dd185 and this one looks like it was missed.

Some of the other files changed in 7ee5843 were later consolidated into
a root `load_paths.rb` file in 9f01dff which was later removed in
2abcdfd.
2022-06-20 00:29:39 -04:00
Brad Trick 52222b6d29 Set `skip_dev_gems` to be a `class_option` 2022-06-20 00:06:39 -04:00
Eileen M. Uchitelle c00c07b66e
Merge pull request #45380 from seejohnrun/remove-multi-use-assert_called_with
Remove the multi-call form of assert_called_with
2022-06-16 17:54:01 -04:00
Gannon McGibbon c47e663750
Merge pull request #45377 from gmcgibbon/update_migration_docs
Add more detailed description to migration generator
2022-06-16 12:49:17 -05:00
Gannon McGibbon 179024de99 Add more detailed description to migration generator 2022-06-16 12:11:05 -05:00
HParker 3a04c7b339 Add configurable deprecation warning for singular associations
This removes the singularize from `where` which runs on all `expand_from_hash` keys which might be reflections or column names. This saves a lot of time by avoiding singularizing column names.

Previously in https://github.com/rails/rails/pull/45163 the singularize was removed entirely. after some reflection, I think it is better to at least give a warning for one release since `where` is a very popular API and the problems you can run into with incorrect relation could be hard to debug.

Configurable with `ActiveRecord::Base.allow_deprecated_singular_assocaitions_name = false` / `config.active_record.allow_deprecated_singular_assocaitions_name = false`
2022-06-16 09:14:12 -07:00
John Crepezzi df0de681dc Remove the multi-call form of assert_called_with
The `assert_called_with` helper allows passing a multi-dimensional array to
mock multiple calls to the same method for a given block. This works
fine now, but when adding support for real kwargs arguments to line up with
recent upgrades in Minitest, this approach is no longer workable because
we can't pass multiple sets of differing kwargs.

Rather than complicated this method further, this commit removes the
multi-call form of `assert_called_with` and modifies the tests that
currently make use of that functionality to just use the underlying
`Minitest::Mock` calls.

Co-authored-by: Eileen M. Uchitelle <eileencodes@gmail.com>
2022-06-16 11:13:57 -04:00
Alex Ghiculescu 52e1ea4fba Make `sqlite3_adapter_strict_strings_by_default` work from an initializer
https://github.com/rails/rails/pull/45346 added an entry to new framework defaults, this PR ensures that configuration works and adds a test for it.
2022-06-15 15:20:45 -05:00
Eileen M. Uchitelle fd0f114f95
Merge pull request #45368 from eileencodes/move-db-and-shard-selector-middleware-to-railtie
Move db and shard selector initalizer to Railties
2022-06-15 13:27:06 -04:00
Asherah Connor ec34400abb
Behaviour constant deprecation fix (#45367)
* Add failing test for Behaviour deprecated alias

* Correct DeprecatedConstantProxy use

* DeprecatedConstantProxy docs indicate "full" constant names
2022-06-15 10:21:17 -07:00
eileencodes d179383284
Move db and shard selector initalizer to Railties
In #45162 it was discovered that the multi_db generator that was created
for 7.0 doesn't work correctly because that file is loaded _after_ the
initializer in active record is run. I tried moving everything to an
after_initialize but the middleware stack is frozen at that point. I
also attempted to fix this in #45353 but it just didn't feel right to
have to deprecate this behavior that _should_ work.

I then realized that most of the middleware in Rails is installed in the
middleware stack file in railties. If I move the middleware installation
to this file, everything works as necessary.

The only caveat is we need to check if `config` responds to
`active_record` but I think that should be fine - we already do that in
the framework defaults configuration.

Fixes #45162
2022-06-15 12:26:27 -04:00
fatkodima 21a6dbd313 Enable strict strings mode for `SQLite3Adapter`
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2022-06-14 23:59:17 +03:00
Rafael Mendonça França 4962e03683
Merge pull request #45280 from cbothner/run-transactional-callbacks-on-instances-most-likely-to-match-database-state
Run transactional callbacks on instances most likely to match DB state
2022-06-14 15:48:18 -04:00
Cameron Bothner 936a862f3c
Run transactional callbacks on instances most likely to match DB state 2022-06-14 13:34:25 -04:00
Étienne Barrié 9578865329 Skip Active Storage and Action Mailer if Active Job is skipped
If you use either of these frameworks, Active Job is used. That means
that only skipping Active Job will not really skip it, and whenever
app:update runs, Active Job will be added back.
2022-06-14 18:04:28 +02:00
Étienne Barrié 85a31f4cdc Correctly check if frameworks are disabled when running app:update
Co-authored-by: Paulo Barros <paulo@paulobarros.me>
2022-06-14 14:31:42 +02:00
Xavier Noria 3bcd48f6d8 Require Zeitwerk 2.6 2022-06-13 23:43:42 +02:00
Gannon McGibbon fff53e4455 Delegate model generator description to orm hooked generator
Use orm hooked generator description for model generator help.
2022-06-10 13:16:21 -05:00
Eileen M. Uchitelle 7c1165c8c8
Merge pull request #45322 from eileencodes/fix-ruby-trunk-did-you-mean
Fix did you mean tests for ruby-trunk (3.2)
2022-06-10 13:30:38 -04:00
eileencodes 935120fdfd
Fix did you mean tests for ruby-trunk (3.2)
In
f075be3dcb
did_you_mean and error_highlight now use `detailed_message` over
`message` to display errors.

For cases where we are testing `message`, in 3.2 and above we need to
test against `detailed_message` instead.

As far as I can tell in a Rails console when these errors are raised the
`detailed_message` is used so we shouldn't need to make other changes to
Rails. The only case where this isn't true is in the Railties changes -
we are explicitly formatting the did you mean message so we need to be
sure to call `detailed_message` here.

This fixes most of the failing tests for ruby-trunk.
2022-06-10 13:06:42 -04:00
Jean Boussier 115be62709 Wrap rails runner in executor
The main reason is to automatically report uncaught exceptions
since `rails runner` is often used for cron tasks and such.
2022-06-10 14:16:49 +02:00
Lachlan Sylvester 7f509ed7be remove call to conditionally configure legacy_connection_handling 2022-06-10 15:19:16 +10:00
eileencodes 866598d51b
Fix shared config feature in 3-tier config
Rails allows you to use a `shared` entry in the database yaml which gets
merged into other entries. This was broken when using a 3-tier config.

The change here ensures we're looping through all the configs. We know
we have a 3-tier config if the config is a hash and all the values
inside that config are a hash. If so we need to keep looping, otherwise
we have a standard 2-tier config.

Fixes #
2022-06-09 08:29:29 -04:00
Jean Boussier 82095de39f
Merge pull request #45293 from ghiculescu/cache_format_version_setting
Correctly read the `cache_format_version` setting on boot
2022-06-08 20:55:15 +02:00
Alex Ghiculescu 08352a2478 Correctly read the `cache_format_version` setting on boot
Fixes https://github.com/rails/rails/issues/45289
2022-06-08 13:21:29 -05:00
John Hawthorn 3ab1616325 Use AS::N build_handle API in Rails::Rack::Logger
Rails::Rack::Logger is one of the few (the only?) places where we aren't
able to use the preferred AS::N.instrument API with a block. This is
because we want to finish the event when the Rack body is closed, rather
than when the status and headers are first returned.

This switches to using the low-level `build_handle` API, which allows
safe interleaving of events and doesn't make use of thread or fiber
locals.
2022-06-06 15:51:02 -07:00
John Hawthorn 2c1c65b83b
Merge pull request #45251 from jhawthorn/deprecated_constant_for_module
Fix includes of deprecation proxy modules
2022-06-06 10:07:58 -07:00
Jonathan Hefner 5f08722c40
Merge pull request #45206 from jonathanhefner/puma-config-omit-workers-and-preload_app
Omit `workers` and `preload_app!` from Puma config
2022-06-03 17:12:36 -05:00
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
John Hawthorn c81a9bca11 Fix name of deprecated constant
The first argument to DeprecatedConstantProxy should be the old constant
name. I suspect this was automatically corrected by accident.
2022-06-02 18:13:31 -07:00
Jean Boussier 920fcce54c
Merge pull request #45230 from natematykiewicz/actionmailbox_unroutable_routes
Remove 4 unroutable routes from ActionMailbox
2022-06-01 13:33:05 +02:00
Nate Matykiewicz c9e48feef2
Remove 4 unroutable routes from ActionMailbox
I was auditing which routes in my app do not actually a
have corresponding controller action. ActionMailbox's
inbound_mails has these 4 routes defined, which do not
actually work.

GET /rails/conductor/action_mailbox/inbound_emails/:id/edit
PATCH /rails/conductor/action_mailbox/inbound_emails/:id
PUT /rails/conductor/action_mailbox/inbound_emails/:id
DELETE /rails/conductor/action_mailbox/inbound_emails/:id
2022-05-31 15:38:45 -05:00
Étienne Barrié a627ef47ea Hide rails:all from rails help
It's already listed as a Rake task.
2022-05-31 11:13:15 +02:00
Étienne Barrié 3d52212a0c Define Thor tasks for test subcommands
This avoids loading the Rakefile, which results in the app booting
twice, once in the development environment to load the Rake tasks, and
then another time in a fork to run the test runner in the test
environment.

Using Thor tasks with no parameters means passing arguments to the task
raises, whereas Rake accepts additional arguments that are not used:

    $ bin/rake test:system SOMETHING=anything

Similarly, with Rake you can use --trace which won't work here.
2022-05-31 11:13:15 +02:00
Brad Trick 958146b3e4 Fix incorrect paths in generator tests
This commit fixes three `assert_no_file` tests with incorrect paths.
2022-05-30 01:06:06 -04:00
fatkodima 580da90fce Pass additional connection options to `psql` when running `rails dbconsole` 2022-05-30 00:02:51 +03:00
Gannon McGibbon 01f58d62c2
Merge pull request #45180 from gmcgibbon/deprecate_behaviour_constant
Deprecate behaviour constant
2022-05-27 09:06:54 -04:00
Gannon McGibbon 3dad2919d5 Rename behaviour to behavior in documentation 2022-05-26 17:14:18 -04:00
Gannon McGibbon 52989bf7cc Rename Deprecate Rails::Generators::Testing::Behaviour to Behavior 2022-05-26 17:14:16 -04:00
eileencodes 58f6710e2f
Allow setting db with use_postgresql tests
If more than one test is using `use_postgresql` for it's tests and both
need to run `db:create` those tests will fail often due to them
running in parallel. I tried turning off parallelization for these tests
and they still ran in separate processes. Ultimately though, turning off
parallelization means we don't aren't testing parallelization. Instead I've
added `Process.pid` to the database name so it creates a database
specifically for that test. For cases where we need to set an explict
name a name can be passed in.

I also added an ensure to one of the tests so that the databases get
cleaned up and not left behind.

Fixes #45114
Fixes #45158
2022-05-26 11:01:39 -04:00
Jean Boussier 7a15d15169
Merge pull request #45142 from jonathanhefner/action_mailer-base-no-load-action_contoller-base
Avoid loading `ActionController::Base` when loading `ActionMailer::Base`
2022-05-21 08:17:40 -07:00
Jonathan Hefner 7415b93580 Avoid ActionController on ActionMailer::Base load
This refactor avoids unnecessarily loading `ActionController::Base` when
loading `ActionMailer::Base`.

Before:

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ ActionMailer::Base } }'
Calculating -------------------------------------
                load    10.013M memsize (     1.372M retained)
                        78.341k objects (    14.363k retained)
                        50.000  strings (    50.000  retained)
```

After:

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ ActionMailer::Base } }'
Calculating -------------------------------------
                load     5.043M memsize (   729.741k retained)
                        38.854k objects (     7.809k retained)
                        50.000  strings (    50.000  retained)
```
2022-05-20 11:57:34 -05:00
Bernie Chiu cdce275f70
Rotate default logs on each 100MB 2022-05-20 16:42:17 +08:00
Jonathan Hefner 702551d86f Enroll new apps in decrypted diffs of credentials
Users, especially those who are creating an app for the first time,
might not be aware of the `rails credentials:diff --enroll` command.
This commit enrolls new apps in decrypted diffs by default so that users
benefit automatically.  This behavior can be opted out of with the app
generator's `--skip-decrypted-diffs` flag.
2022-05-19 15:20:03 -05:00
Jonathan Hefner da651a21e1 Support declarative-style test name filters
This makes it possible to run a declarative-style test such as:

```ruby
class MyTest < ActiveSupport::TestCase
  test "does something" do
    # ...
  end
end
```

Using its declared name:

```bash
$ bin/rails test test/my_test.rb -n "does something"
```

Instead of having to specify its expanded method name:

```bash
$ bin/rails test test/my_test.rb -n test_does_something
```

Co-authored-by: Eugene Kenny <elkenny@gmail.com>
2022-05-19 08:50:26 -05:00