Commit Graph

79776 Commits

Author SHA1 Message Date
Andrew White
3dd0af563b
Merge pull request #41873 from rails/prevent-deprecation-warning-with-yaml-twz
Use YAML.load_tags/dump_tags to prevent deprecation warnings
2021-04-08 12:04:26 +01:00
Ryuta Kamizono
12c4b77c55 SecureRandom.urlsafe_base64 doesn't have padding: false keyword argument
Actually it is regarded truthy as `padding = { padding: false }`.

https://docs.ruby-lang.org/en/2.7.0/Random/Formatter.html#method-i-urlsafe_base64
2021-04-08 18:08:55 +09:00
Xavier Noria
d0719825ac
Merge pull request #41877 from Shopify/simplify-constantize
Directly delegate `constantize` to `Object.const_get`
2021-04-08 10:15:02 +02:00
Jean Boussier
7057ccf656 Directly delegate constantize to Object.const_get
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
```
2021-04-08 09:58:52 +02:00
Andrew White
db9ba18659
Use YAML.load_tags/dump_tags to prevent deprecation warnings
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.
2021-04-07 23:31:09 +01:00
Jean Boussier
57cbf4136f
Merge pull request #41866 from etiennebarrie/simplify-active-model-record-registry
Simplify ActiveModel & ActiveRecord Type::Registry
2021-04-07 21:31:37 +02:00
Étienne Barrié
81d0653f84 Simplify ActiveModel & ActiveRecord Type::Registry
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>
2021-04-07 09:59:55 -04:00
eileencodes
b8b1c9eba9
Fix missing link in deprecation 2021-04-07 08:15:48 -04:00
Ryuta Kamizono
7fd8079ef2
Merge pull request #41789 from kamipo/update_cache_key_after_mutation
Clear `@cache_keys` cache after `update_all`, `delete_all`, `destroy_all`
2021-04-07 16:47:17 +09:00
Jean Boussier
fe8f47b425
Merge pull request #41831 from Shopify/as-cache-clock-gettime
Allow to set cache expiry as an absolute timestamp
2021-04-07 09:10:02 +02:00
John Hawthorn
a9c0002409
Merge pull request #41846 from jhawthorn/remove_template_fallbacks
Remove FallbackFileSystemResolver
2021-04-06 18:20:30 -07:00
Ryuta Kamizono
bc488431ae
Merge pull request #41788 from pbstriker38/check_table_name_constraint_mariadb
Add support for check_constraints with the same name on different tables
2021-04-07 09:16:59 +09:00
Eileen M. Uchitelle
564a26d134
Merge pull request #41859 from eileencodes/deprecate-legacy-connection-handling
Deprecate legacy_connection_handling
2021-04-06 19:38:37 -04:00
eileencodes
634bf89df3
Deprecate legacy_connection_handling
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.
2021-04-06 18:57:22 -04:00
John Hawthorn
fb6b0a51b3 Remove FallbackFileSystemResolver
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.
2021-04-06 14:20:48 -07:00
John Hawthorn
da795a678b
Merge pull request #41858 from jhawthorn/fix_build
Fix build on Ruby 3.0.1
2021-04-06 11:32:32 -07:00
Xavier Noria
27624077e6 Delete orphan autoloading fixtures
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.
2021-04-06 20:14:10 +02:00
John Hawthorn
23996030ba Fix build 2021-04-06 11:13:33 -07:00
Rafael França
c0a5e8db5e
Merge pull request #41314 from etiennebarrie/fix-rake-test-db
Fix rake test:db loading in development
2021-04-06 13:50:05 -04:00
Jean Boussier
9de17ac4a4 Allow to set cache expiry as an absolute timestamp
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.
2021-04-06 10:49:05 +02:00
John Hawthorn
0ff395e1b1
Merge pull request #41790 from jhawthorn/preloader_smart_batching
"Smart" ActiveRecord Preloader batching
2021-04-05 10:14:07 -07:00
Andrew White
b206e2f13d
Merge pull request #41735 from ags/private-no-store-cache-control
Allow 'private, no-store' Cache-Control header
2021-04-05 15:28:20 +01:00
Andrew White
725f8f4c85
Merge pull request #41835 from rails/deprecate-astwz-name-override
Deprecate ActiveSupport::TimeWithZone.name
2021-04-05 14:52:27 +01:00
Alex Smith
0680658624 Allow 'private, no-store' Cache-Control header
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
2021-04-05 14:20:17 +10:00
George Claghorn
b80a2bdeb9
Active Storage: upgrade to mini_mime 1.1.0
Fix validating uppercase variant formats. Closes #41796.
2021-04-04 22:44:02 -04:00
Andrew White
3f4b41a6f5
Deprecate ActiveSupport::TimeWithZone.name
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.
2021-04-04 16:57:51 +01:00
Eugene Kenny
80bd07a61a
Merge pull request #41611 from jonathanhefner/populate-argv-in-command-invoke
Populate ARGV with Rails::Command.invoke args
2021-04-03 23:43:15 +01:00
Xavier Noria
208635574a
Merge pull request #41833 from basecamp/exclude-performance-from-isolated
Exclude encryption performance tests from *:isolated_test tasks
2021-04-03 23:48:57 +02:00
Jorge Manrubia
1fff866dd1 Exclude encryption performance tests from isolated runs
Encryption performance tests were meant to be excluded from the builds,
however they were still being executed when running `isolated:` tests
for active record adapters.

See https://buildkite.com/rails/rails/builds/76249#e7605d50-87be-445e-a9ae-a5761c996597/1512-1531
2021-04-03 23:11:30 +02:00
Xavier Noria
af27a25f19 Remove DependenciesTestHelpers 2021-04-03 19:24:12 +02:00
Xavier Noria
5f70349b05 Remove with_autoloading_fixtures from the AS::Testing::ConstantLookup test suite
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.
2021-04-03 19:24:12 +02:00
Jonathan Hefner
ddcfde2226 Populate ARGV with Rails::Command.invoke args
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.
2021-04-03 10:12:52 -05:00
George Claghorn
432bc68a2c Fix more Book references.
Follow-up to 434fb39.
2021-04-03 08:31:59 -04:00
George Claghorn
b4120d0a30 Fix lingering references to Book
Follow-up to 434fb39.
2021-04-03 08:20:42 -04:00
Ricardo Díaz
434fb39d47
Add new "encrypted_books" table to the schema
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))$/"
```
2021-04-03 08:00:01 -04:00
Tietew
92b8cda4c9
secure_compare: Check byte size instead of length
Match fixed_length_secure_compare's guard clause.

References #39142.
2021-04-02 12:45:29 -04:00
Vladislav
d264276288 RemoteConnection#disconnect: fix ArgumentError on ruby 3.0 2021-04-02 12:24:54 -04:00
Carlos Antonio da Silva
e63f8205d1 Tweak AR Encryption guide for better highlighting [ci skip] 2021-04-02 11:04:28 -03:00
Jorge Manrubia
224c9b34cb
Add Active Record encryption to CHANGELOG 2021-04-02 07:40:00 -04:00
Ryuta Kamizono
7e1820d71b
Merge pull request #41818 from ricardotk002/fix-missing-require
Fix seemingly wrong require "lib"
2021-04-02 19:56:11 +09:00
Ricardo Díaz
27b0180232 Remove print statement / uncomment relevant assertion 2021-04-02 01:03:43 -05:00
Ricardo Díaz
b11645eb2b Fix wrong require
This library is used here

https://github.com/rails/rails/blob/1251703/activerecord/lib/active_record/encryption/encryptor.rb#L121

and here

https://github.com/rails/rails/blob/1251703/activerecord/lib/active_record/encryption/encryptor.rb#L135

Reference https://buildkite.com/rails/rails/builds/76198#de7db4af-b8ca-46de-986f-0db34b1d4ddc
2021-04-02 01:00:37 -05:00
Ryuta Kamizono
1251703c4d Fix typo [ci skip] 2021-04-02 14:38:00 +09:00
Sampat Badhe
2032daa415
Fix typos encryption doc (#41817)
* fix typo

[ci skip]
2021-04-02 14:24:43 +09:00
Jorge Manrubia
3648c25cad Minor encryption guide tweaks and corrections 2021-04-01 14:52:42 -07:00
Jeremy Daer
07c3eee478
Merge pull request #41659 from basecamp/active-record-encryption
Add encryption to Active Record
2021-04-01 14:14:38 -07:00
Guillermo Iguaran
3583d82ea2
Merge pull request #41812 from rokbot/fix/guides-mailer-basics
[ci skip] fix on guides mailer_basics avoid ActiveModel::ForbiddenAttributesError
2021-04-01 13:26:30 -07:00
Jorge Manrubia
5a6352c072 Fix deterministic queries that were broken after #41068
This is adding yet another patch to make them work. This system needs to
be reworked as it's currently very brittle.
2021-04-01 22:10:59 +02:00
John Hawthorn
20b9bb1de0 Intelligent batch preloading
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>
2021-04-01 12:52:43 -07:00
Rafael França
3a32f44745
Merge pull request #41809 from bbuchalter/bb.improved_strong_params_logging
Provide context when logging unpermitted parameters
2021-04-01 14:38:45 -04:00