`deprecate_constant` will warn whenever the constant is referenced
instead of when the constant is a method receiver, which increases the
likelihood that the warning will be seen. Additionally,
`DeprecatedConstantProxy` prevents using the constant as a superclass,
such as in `class MyClass < SomeDeprecatedConstant`.
* Add after_routes_loaded hook
This hook can be used to trigger engine behavior that should only happen
after application routes have been loaded (or reloaded).
* Add changelog entry
* Add note about new after_routes_loaded railtie config to guides
[Rafael Mendonça França + Chris Salzberg]
Previously, assignment would succeed but silently not write to the
database.
The changes to counter_cache are necessary because incrementing the
counter cache for a column calls []=. I investigated an approach to use
_write_attribute instead, however counter caches are expected to resolve
attribute aliases so write_attribute/[]= seems more correct.
Similarly, []= was replaced with _write_attribute in merge_target_lists
to skip the overriden []= and the primary key check. attribute_names
will already return custom primary keys so the primary_key check in
write_attribute is not needed.
Co-authored-by: Alex Ghiculescu <alex@tanda.co>
Previously, encrypted attributes could be added to an application's
filter_parameters which would filter the attribute values from logs.
This commit makes the add_to_filter_parameters additionally add
encrypted attributes to records' filter_attributes, which allows them
to be filtered when models are inspected (such as in the console).
A few `AppGeneratorTest` tests require running Bundler. When Bundler
tries to resolve `gem "rails"`, it searches for an invalid version
number (for a version that hasn't been released yet). Doing so is slow
and prints many lines of error output. Furthermore, the same tests
print additional output via the commands that the generator runs after
Bundler.
This commit adds a `run_generator_and_bundler` helper which points
`gem "rails"` to the current repository, and silences any additional
output from the generator.
**Before**
```
$ cd railties
$ bin/test test/generators/app_generator_test.rb --verbose --seed 520 -n '/test_hotwire|test_css_option_with_asset_pipeline_tailwind|test_css_option_with_cssbundling_gem/'
# Running:
Could not find gem 'rails (~> 7.1.0.alpha)' in rubygems repository https://rubygems.org/ or installed locally.
The source contains the following gems matching 'rails':
* rails-0.8.0
* rails-0.8.5
* rails-0.9.0
...431 MORE LINES...
* rails-7.0.3
* rails-7.0.3.1
* rails-7.0.4
Could not find gem 'rails (~> 7.1.0.alpha)' in locally installed gems.
The source contains the following gems matching 'rails':
...MORE LINES...
AppGeneratorTest#test_hotwire = 26.30 s = .
Could not find gem 'rails (~> 7.1.0.alpha)' in rubygems repository https://rubygems.org/ or installed locally.
The source contains the following gems matching 'rails':
* rails-0.8.0
* rails-0.8.5
* rails-0.9.0
...431 MORE LINES...
* rails-7.0.3
* rails-7.0.3.1
* rails-7.0.4
Could not find gem 'rails (~> 7.1.0.alpha)' in locally installed gems.
The source contains the following gems matching 'rails':
...MORE LINES...
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
Done in 645ms.
AppGeneratorTest#test_css_option_with_asset_pipeline_tailwind = 45.64 s = .
Could not find gem 'rails (~> 7.1.0.alpha)' in rubygems repository https://rubygems.org/ or installed locally.
The source contains the following gems matching 'rails':
* rails-0.8.0
* rails-0.8.5
* rails-0.9.0
...431 MORE LINES...
* rails-7.0.3
* rails-7.0.3.1
* rails-7.0.4
Could not find gem 'rails (~> 7.1.0.alpha)' in locally installed gems.
The source contains the following gems matching 'rails':
...MORE LINES...
npm WARN set-script set-script is deprecated, use `npm pkg set scripts.scriptname="cmd" instead.
app/assets/builds/application.js 55b
app/assets/builds/application.js.map 93b
npm WARN set-script set-script is deprecated, use `npm pkg set scripts.scriptname="cmd" instead.
AppGeneratorTest#test_css_option_with_cssbundling_gem = 51.93 s = .
Finished in 123.877633s, 0.0242 runs/s, 0.2180 assertions/s.
3 runs, 27 assertions, 0 failures, 0 errors, 0 skips
```
**After**
```
$ cd railties
$ bin/test test/generators/app_generator_test.rb --verbose --seed 520 -n '/test_hotwire|test_css_option_with_asset_pipeline_tailwind|test_css_option_with_cssbundling_gem/'
# Running:
AppGeneratorTest#test_hotwire = 10.00 s = .
AppGeneratorTest#test_css_option_with_asset_pipeline_tailwind = 22.61 s = .
AppGeneratorTest#test_css_option_with_cssbundling_gem = 30.77 s = .
Finished in 63.386282s, 0.0473 runs/s, 0.4260 assertions/s.
3 runs, 27 assertions, 0 failures, 0 errors, 0 skips
```
Right now they are being eager loaded that means they are being loaded
in the production environment unnecessarily.
All we need is for those paths to be autoloaded in development, so
code reload works.
This method was failing to return the connection to the correct state
which would break tests when eager loading the application. What's
happening is that when we check `schema_up_to_date` when the application
is eager loaded all the models are eager loaded as well so it sees that
ApplicationRecord has a connection already but that connection is set to
the wrong one. It doesn't get replaced with the right one so we see
errors about looking for tables in the wrong database. This doesn't
happen when eager loading is off because ApplicationRecord isn't set and
gets initialized with the correct connection (from it's
`connects_to/establish_connection` call).
I also refactored this to pull `needs_update` into a method and make the
loop easier to read.
This commit adds `Rails.deprecator`, which currently returns
`ActiveSupport::Deprecation.instance`. This commit also replaces all
usages of `ActiveSupport::Deprecation.warn` in `railties/lib` with
`Rails.deprecator.warn`.
This commit adds `ActiveModel.deprecator`, and adds it to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.
This commit adds `ActionText.deprecator`, and adds it to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.
This commit adds `ActionMailbox.deprecator`, and adds it to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.
This commit adds `ActionCable.deprecator`, and adds it to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.
This commit adds `ActiveStorage.deprecator` and replaces all usages of
`ActiveSupport::Deprecation.warn` in `activestorage/lib` and
`activestorage/app` with `ActiveStorage.deprecator`.
Additionally, this commit adds `ActiveStorage.deprecator` to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.
This commit adds `ActiveJob.deprecator` and replaces all usages of
`ActiveSupport::Deprecation.warn` in `activejob/lib` with
`ActiveJob.deprecator`.
Additionally, this commit adds `ActiveJob.deprecator` to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.
This commit also removes a defunct `ActiveSupport::Deprecation.silence`
call that was added in 9eb4b4ed01 but not
removed when the deprecation was completed in
10bd5e59c3.
This commit adds `ActionView.deprecator` and replaces all usages of
`ActiveSupport::Deprecation.warn` in `actionview/lib` with
`ActionView.deprecator`. This commit also replaces a call to Ruby's
`Module#deprecate_constant` with Rails' `DeprecatedConstantProxy`, so
that its deprecation behavior can be configured using
`ActionView.deprecator`.
Additionally, this commit adds `ActionView.deprecator` to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.
This commit also removes a few defunct `assert_deprecated` calls that
were not failing because they were nested in `assert_raises`, and the
raised error prevented checking the deprecation. (One was mistakenly
kept in d52d773946 when converting
`test_render_file_with_errors` to `test_render_template_with_errors`;
the other two were added in dd9991bac5 but
not removed when the deprecation was completed in
85ecf6e4098601222b604f7c1cbdcb4e49a6d1f0.)
This fixes two warnings like the following when running
`rails/railties/test/application/initializers/frameworks_test.rb`:
```
warning: possibly useless use of a constant in void context
```
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`.
This fixes a few warnings like the following when running
`railties/test/application/configuration_test.rb`:
```
warning: possibly useless use of :: in void context
```
These `ActiveJob::Base` references were added in
b4fffc3c68. However, that same commit
makes these references unnecessary by setting configuration in an
`after_initialize` block (in addition to an `on_load(:active_job)`
block).
This fixes the following warning when running
`railties/test/generators/plugin_generator_test.rb`:
```
warning: character class has duplicated range
```
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`.
This commit adds `AbstractController.deprecator` and
`ActionController.deprecator`, and replaces all usages of
`ActiveSupport::Deprecation.warn` in `actionpack/lib/action_controller`
with the latter.
Additionally, this commit adds `ActionController.deprecator` to
`Rails.application.deprecators`. Because `AbstractController` does not
have its own railtie to do the same, `AbstractController` and
`ActionController` use the same deprecator instance. Thus, both can be
configured via `Rails.application.deprecators[:action_controller]` or
via config settings such as `config.active_support.report_deprecations`.
These were added in cdce275, 5d0c2b0, and 5256c90
For the new MessageVerifier and MessageEncryptor defaults, I modeled the
documentation after cb76ede. The goal is to warn users that they should
pay attention to the config and not just uncomment it without doing
additional work.
I also added an extra note to log_file_size since it is the first
load_default I'm aware of that is environment dependent.
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
The [pipe operator](https://ruby-doc.org/core-3.1.2/Array.html#method-i-7C) will return the union of the two sets, with duplicates removed. That causes problems if there are two values in the arguments that are the same.
This change still avoids adding a duplicate `--skip-bootsnap` option, but doesn't remove duplicates which allows for args like ["--option1", "value", "--option2", "value"] to work as expected.
Fixes#46347
This commit adds `ActiveSupport.deprecator` and replaces all usages of
`ActiveSupport::Deprecation.warn` in `activesupport/lib` with
`ActiveSupport.deprecator`.
Additionally, this commit adds `ActiveSupport.deprecator` to
`Rails.application.deprecators` so that it can be configured using e.g.
`config.active_support.report_deprecations`.
This commit adds `ActiveRecord.deprecator` and replaces all usages of
`ActiveSupport::Deprecation.warn` in `activerecord/lib` with
`ActiveRecord.deprecator`.
Additionally, this commit adds `ActiveRecord.deprecator` to
`Rails.application.deprecators` so that it can be configured using e.g.
`config.active_support.report_deprecations`.
The `rails db:version` task makes no effort today to display information for multi-database applications.
This brings up this simplistic tasks up to parity with the rest of the DB tasks that support multi-database applications.
This is accomplished by following the pattern of making the non-namespaced task (i.e. `db:version`) to output a multi-line string, iterating through all defined databases for the current environment in `database.yml`
It also adds a namespaced instance of the task for each database defined (e.g. `db:version:animals`).
**A hidden change, but critical (for the purposes that I'm working on), that is happening here** is that database configurations with `database_tasks: false` will be excluded from the logic in this task – due to the usage of the `ActiveRecord::Base.configurations.configs_for` method, which by default has `include_hidden: false`!
This applies the following configs to `Rails.application.deprecators`,
which then applies them to `ActiveSupport::Deprecation.instance`:
* `config.active_support.report_deprecations`
* `config.active_support.deprecation`
* `config.active_support.disallowed_deprecation`
* `config.active_support.disallowed_deprecation_warnings`