All the complexity of that method was to work around various
problems caused by Ruby's constant lookup semantic as well
as the classic autoloader shortcommings.
Now that Rails require Ruby 2.7 I don't think we need anything
more than just `Object.const_get`.
```ruby
require 'benchmark/ips'
require 'active_support/all'
module Foo
module Bar
module Baz
end
end
end
def patched_constantize(name)
Object.const_get(name)
end
Benchmark.ips do |x|
x.report('orig') { ActiveSupport::Inflector.constantize("Foo::Bar::Baz") }
x.report('patched') { patched_constantize("Foo::Bar::Baz") }
x.compare!
end
```
```
Warming up --------------------------------------
orig 69.668k i/100ms
patched 391.385k i/100ms
Calculating -------------------------------------
orig 705.027k (± 1.9%) i/s - 3.553M in 5.041486s
patched 3.935M (± 1.1%) i/s - 19.961M in 5.072912s
Comparison:
patched: 3935235.5 i/s
orig: 705027.2 i/s - 5.58x (± 0.00) slower
```
The default behavior of the Psych gem for Ruby classes is to call the
`name` method to generate a tag for encoding. However this causes a
stream of deprecation warnings whenever ActiveSupport::TimeWithZone
instances are encoded into YAML. By utilising the load_tags/dump_tags
configuration we can prevent Psych from calling the `name` method and
thereby prevent the triggering of the deprecation warnings.
ActiveRecord::Type::Registry doesn't need to inherit from
ActiveModel::Type::Registry, and it makes both classes more simple.
Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
This deprecates `legacy_connection_handling` via the
`connection_handlers` setter. This is called from the ActiveRecord
Railtie on boot and since most applications don't set this themselves
this will prevent the deprecation from being raised multiple times for a
test run or in development.
I've also updated the guides to include a migration path for
applications using the deprecated methods. The majority of applications
won't need to make any changes.
This removes FallbackFileSystemResolver, LookupContext#with_fallbacks,
and LookupContext.fallbacks.
These used to exist to support `render file:`, and rendering templates
outside of the defined view paths. `render file:` has since been changed
to not use template resolution, and to only render absolute paths.
These were no longer callable through any public API.
Rails now delegates autoloading to Zeitwerk, and therefore does not need to test
autoloading itself. Zeitwerk has test coverage, in Rails we only need to test
the integration.
We are gradually trimming AS::Dependencies, and the AS test suite. With the
removal of DependenciesTestHelpers and client code in af27a25, these fixtures
became orphan.
Three of them are left. They are to be autoloaded with Module#autoload because
they raise errors when the file is evaluated. Their current use cases are
already committed.
Sometime it can be useful to set a cache entry expiry
not relative to current time, but as an absolute timestamps,
e.g.:
- If you want to cache an API token that was provided to
you with a precise expiry time.
- If you want to cache something until a precise cutoff
time, e.g. `expires_at: Time.now.at_end_of_hour`
This leaves the `@created_at` variable in a weird state,
but this is to avoid breaking the binary format.
https://github.com/rails/rails/pull/39461 changed the `no-store`
directive for the `Cache-Control` header to be exclusive, i.e. when
setting `Cache-Control` to `private, no-store`, this is simplified to
just `no-store`. `private` should typically be superfluous there, but
it's not always.
For instance, Fastly "does not currently respect no-store or no-cache
directives" and says that "if you need to prevent caching by both Fastly
and web browsers, we recommend combining the private directive with
max-age=0 or no-store".
https://docs.fastly.com/en/guides/configuring-caching#do-not-cache
Since it's not possible to override this directive reduction behaviour,
the changes in #39461 prevent Fastly users from upgrading Rails.
This changes the behaviour to allow setting a 'private, no-store' header
when private is specified - similar to how 'public' can be specified
when 'no-cache' is, but not as a default.
Fixes https://github.com/rails/rails/issues/40798
In c00f2d2 the `name` method was overridden to return 'Time' instead of
the real class name 'ActiveSupport::TimeWithZone'. The reasoning for
this is unclear and it can cause confusion for developers assuming that
name is returning the real class name. Since we don't know why this
was added, we're deprecating the method first to give developers a
chance to provide us with feedback and look to fix any issues that arise.
The rewritten test is not super clean with the manual cleanup etc.. If this is a
one-off it's not a big deal. However, if in subsequent rewrites I spot more
occurrences of this pattern, then I'll refactor.
Follow-up to #38495.
Similar to #40994, but for all Rails commands. Programmatic and CLI
invocations of Rails commands will still behave identically, and `ARGV`
will still be isolated between invocations.
Reverts #40994.
Reusing the "books" one could cause interferences when fixtures are
loaded in a very specific order such as:
https://buildkite.com/rails/rails/builds/76217#ee4ce591-e6c1-4a0d-a7db-1f83647d141e
Reproduction script:
```
activerecord $ bin/test -v --seed 23607 -n "/^(?:EagerAssociationTest#(?:test_preloading_a_regular_association_with_a_typo_through_a_polymorphic_association_still_raises)|ActiveRecord::Encryption::EncryptableFixtureTest#(?:test_fixtures_get_encrypted_automatically)|ViewWithoutPrimaryKeyTest#(?:test_attributes|test_reading))$/"
```
This examines all the association branches we are being asked to preload
and will delay loading an association if it's likely that we find a
similar association later and can batch them together.
For example, when loading
Author.preload(:posts, favorite_authors: :posts).first
The preloader now knows to delay loading the top level posts so that it
can load both the top level :posts and the :posts from the favourite
authors associations together.
Co-authored-by: Dinah Shi <dinahshi@github.com>