Commit Graph

8884 Commits

Author SHA1 Message Date
Gert Goet 53ede786fc Ensure codeblocks are rendered as such for (min|max)imum
Make indentation consistent for all codeblocks in file.

[ci-skip]
2022-01-07 12:33:40 +01:00
Kev 0ab5a3a4ab Allow subsecond resolution in `travel_to` helper
The `travel_to` helper didn’t support subsecond time traveling in order
to prevent problems with external services, such as MySQL. This,
however, makes it impossible to test features that use durations less
than a second ("subsecond").

This therefore allows `travel_to` to stub `Time.now` with the accurate
time passed to it as `date_or_time` if the `with_usec` optional argument
is set to true:

    Time.now.inspect # => 2022-01-05 22:36:54.613371959 +0000
    travel_to(0.1.seconds.from_now, with_usec: true)
    Time.now.inspect # => 2022-01-05 22:36:54.713371959 +0000
2022-01-06 00:53:35 +01:00
Rafael Mendonça França 0d6af17d66
Merge pull request #43924 from jcmfernandes/message-encryptor-perf-improvements
Improve the performance of ActiveSupport::MessageEncryptor
2022-01-04 18:31:12 -05:00
Mike Dalessio 5e69b7e000
doc: clarify usage of Object.acts_like?
Related to #42292

[skip ci]
2022-01-04 12:26:06 -05:00
Ryuta Kamizono 65766ebcc8 Bump license years to 2022 [ci-skip] 2022-01-01 15:22:15 +09:00
Ryuta Kamizono 9d2533203c Revert "Update the deprecation message for `Enumerable#sum` and `Array#sum`"
This reverts commit 20e20d56ab.

The deprecation message doesn't say when it will be removed, but just
say when it has deprecated.
2021-12-23 16:19:17 +09:00
Ryuta Kamizono 20e20d56ab Update the deprecation message for `Enumerable#sum` and `Array#sum`
Rails 7.0 has already been released.
2021-12-23 16:07:19 +09:00
Jean Boussier bc07139db3 Remove feature checking for Class#descendants
Ref: https://bugs.ruby-lang.org/issues/14394#note-38

Based on Matz's last comment, it's not so clear whether `Class#descendants`
will come back in the same form or at all. So let's not assume anything.
2021-12-22 14:12:13 +01:00
Jean Boussier 912b02ab58 Fix a mistake in DescendantsTracker#descendants for Ruby 3.1 2021-12-21 13:06:52 +01:00
Joao Fernandes 0a0dc95499 Improve the performance of ActiveSupport::MessageVerifier
We can avoid using String#split by calculating the indexes of the
encrypted data, IV, and auth tag in the payload. This increases the
resistance of the solution against ill-formed payloads that don't
include the separator.

This is a follow up to the work in PR #42919.
2021-12-21 11:13:00 +00:00
Jean Boussier 68e9df0257 Ruby 3.1: Handle `Class#subclasses` existing without `Class#descendants`
Since `#subclasses` was introduced a bit after `#descendants`, the feature testing
code assumed that if the former was present, the later would be too.

However it was decided to revert `#descendants` for now, but to keep `#subclasses`
https://bugs.ruby-lang.org/issues/14394#note-33

Since this was totally unexpected, the `#descendants` core_ext and `DescendantsTracker#descendants`
are broken on Active Support 7.0.0 / Ruby 3.1.0-dev.

We now test the existence of both methods to handle this new situation. Since
for now it's planned for `#descendants` to make it back in Ruby 3.2, we keep
checking for it.
2021-12-21 11:41:56 +01:00
Rafael Mendonça França 5f5bd542b3
Fix logger format with Ruby 3.1 2021-12-20 22:36:33 +00:00
Alex Ghiculescu af71e5ef96 Fix flakey Memcache tests 2021-12-13 15:06:03 -06:00
Hartley McGuire 14024c0b80 rm tmpfile added in 340b39e
This appears to have been accidentally added as an artifact of
1d164fdfe1/activesupport/test/file_update_checker_shared_tests.rb (L224)
2021-12-12 21:32:59 -05:00
Rafael Mendonça França a35a380c2c
Remove CHANGELOG that is included in 7.0 2021-12-10 19:03:45 +00:00
Caleb Buxton ffc1e5f889
fix: equivalent negative durations add to the same time (#43795)
* bug: illustrate negative durations don't add to the same time

* fix: equivalent negative durations add to the same time

Co-authored-by: Caleb <me@cpb.ca>
Co-authored-by: Braden Staudacher <braden.staudacher@chime.com>

* Updates CHANGELOG with fix to `ActiveSupport::Duration.build`
2021-12-10 14:03:04 -05:00
Jean Boussier 151ba1ab0c DescendantsTracker: fix the TruffleRuby implementation
Ref: https://github.com/rails/rails/pull/43723

This was pretty much a typo...
2021-12-09 09:38:49 +01:00
Jonathan Hefner 1a4e27e216 Fix assert_called_with with empty args array
`[].all?(Array)` returns `true`.  Thus when an empty `args` array was
passed to `assert_called_with`, `expect` would not be called on the mock
object, eventually leading to an "unmocked method" error.

This commit allows an empty array to be passed as `args`, which behaves
the same as passing `[[]]`.
2021-12-08 12:15:36 -06:00
sampatbadhe 0055b72a3b replace duplicate entries of to_formatted_s with to_fs 2021-12-08 12:31:05 +05:30
Rafael Mendonça França de065c9f7e
Merge pull request #42919 from jcmfernandes/avoid-double-string-split-message-verifier
Avoid unnecessary double string split in ActiveSupport::MessageVerifier#verified
2021-12-07 11:23:19 -05:00
Rafael Mendonça França 83d85b2207
Start Rails 7.1 development 2021-12-07 15:52:30 +00:00
Joao Fernandes 02eda1b950 Extract components from signed messages by calculating their indexes
ActiveSupport::MessageVerifier#verified is causing signed_message to be
split twice: first inside #valid_message? and then inside #verified.
This is ultimately unnecessary.

We can avoid String#split all together by calculating the indexes of the
data and the digest in the payload. This increases the resistance of the
solution against ill-formed payloads that don't include the separator.
2021-12-07 09:44:53 +00:00
Ryuta Kamizono 30ff804ca7 Fix typo in the rdoc for `Pathname#existence` [ci-skip] 2021-12-07 16:01:41 +09:00
Richard Macklin 4954317aac Fix test name in PathnameExistenceTest
This was likely a copy-paste typo from
00fb4e6bbd/activesupport/test/core_ext/object/blank_test.rb (L32)
introduced in 1a14bcb8cd
2021-12-06 21:45:00 -08:00
Rafael Mendonça França 83a3df0136
Add config to disable the `to_s` override in Ruby core classes
This will allow users to take advantage early of Ruby 3.1 optimization
in string interpolation.
2021-12-06 19:22:07 +00:00
Rafael Mendonça França 9aae3ae183
Alias to_formatted_s as to_fs 2021-12-06 19:22:06 +00:00
Rafael Mendonça França 58ecdd0cf2
Deprecate `to_s(format)` in favor of `to_formatted_s(format)`
Ruby 3.1 is going to introduce an [optimization][] that makes interpolation
of some types of objects faster, unless there is a custom implementation
of to_s. Since Rails is overriding `to_s` for a bunch of core classes it
means that this optimization in Rails applications will be disabled.

In order to allow Rails applications to use this optimization in
the future we are deprecating all the reasons we override `to_s` in
those core classes in favor of using `to_formatted_s`.

[optimization]: b08dacfea3
2021-12-06 19:22:05 +00:00
Rafael Mendonça França c2e12e0191
Use `to_formatted_s(:db)` instead of `to_s(:db)` internally
Ruby 3.1 introduced an optimization to string interpolation for some
core classes in b08dacfea3.

But since we override `to_s` in some of those core classes to add behavior
like `to_s(:db)`, all Rails applications will not be able to take advantage
of that improvement.

Since we can use the `to_formatted_s` alias for the Rails specific behavior
it is best for us to deprecate the `to_s` core extension and allow Rails
applications to get the proformace improvement.

This commit starts removing all the `to_s(:db)` calls inside the framework
so we can deprecate the core extension in the next commit.
2021-12-06 19:22:04 +00:00
Sam Bostock 7007d1b2b5
Document ActiveSupport::Testing::Deprecation
Co-authored-by: Sam Jordan <sam.jordan@shopify.com>
Co-authored-by: Sam Bostock <sam.bostock@shopify.com>
2021-12-03 15:04:25 -05:00
Jonathan Hefner 763c219539 Fix flakey test in notifications_test.rb
Example failure: https://buildkite.com/rails/rails/builds/82905#80d6c6ec-943d-4ba3-b360-1ef6c4aa5d89/1012-1022

The test designates the event end time as 0.01 seconds (i.e. 10
milliseconds) after the start time.  It then asserts that the event
duration is 10 ± 0.0001 milliseconds.  This sometimes fails due to
floating point precision errors.

This commit changes the assertion to instead check that the duration is
within 1% of the expected value.
2021-11-30 14:03:32 -06:00
Timo Schilling 115c562927
Fix type in Pathname#existence documentation 2021-11-30 08:37:28 +01:00
Rafael Mendonça França be3ed75ec7
Merge pull request #43718 from esparta/fix_race_conditions_test_cache_v
ActiveSupport::Cache, fix race conditions on test/cache - part V
2021-11-29 16:51:21 -05:00
Rafael Mendonça França 223ba6f81d
Fix documentation of Pathname#existence 2021-11-29 21:49:31 +00:00
Alex Ghiculescu 5046d1cce9 Wrap ActionController::TestCase with Rails executor
Update actionpack/lib/action_controller/test_case.rb

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2021-11-26 17:54:47 -06:00
Rafael Mendonça França c14cb9150e
Revert "Add missing `require "active_support` in XmlMini"
This reverts commit 0181f0edd5.

Users of Active Support should always require the top level file of
the framework before requiring anything else inside it, so we don't
need to require that top level file here.
2021-11-26 19:21:10 +00:00
Vipul A M bd04720c7f
Merge pull request #43731 from shunyama/fix/tiny-typo-fix
[skip ci] Fixed tiny typo
2021-11-26 11:23:07 -05:00
shunyama 4b89f16ad4 [skip ci] fix tiny typo 2021-11-27 00:57:08 +09:00
Jean Boussier 0181f0edd5 Add missing `require "active_support` in XmlMini 2021-11-26 11:51:57 +01:00
Espartaco Palma c677229b2c
ActiveSupport::Cache, Part V - change clear override for MemCached 2021-11-26 01:17:31 -08:00
Rafael Mendonça França 33157e2173
Merge pull request #43726 from timoschilling/add-pathname-existence
add Pathname#existence
2021-11-25 15:48:32 -05:00
Rafael Mendonça França df35d93adf
Merge pull request #43719 from kmcphillips/error-reporter-fallback-callable
Require the ErrorReporter#handle fallback to be a callable
2021-11-25 14:32:15 -05:00
Rafael Mendonça França 100ad4341d
Merge pull request #43324 from ghiculescu/patch-5
Be more explicit about lack of inheritance on `thread_mattr_accessor`
2021-11-25 13:46:36 -05:00
Kevin McPhillips d0eeee03be Require the ErrorReporter#handle fallback to be a callable 2021-11-25 13:33:51 -05:00
Jean Boussier ff5e909b63 DescendantsTracker: fix the TruffleRuby branch 2021-11-25 18:09:44 +01:00
Timo Schilling 1a14bcb8cd add Pathname#existence 2021-11-25 16:51:58 +00:00
Jean Boussier 617c8357f6
Merge pull request #43723 from Shopify/descendant-tracker-3.1
Fix DescendantTracker.clear on Ruby 3.1
2021-11-25 17:50:46 +01:00
Jean Boussier cb82f5f0a4 Fix DescendantTracker.clear on Ruby 3.1
Previously I assumed it was useless, however I was wrong.

The method is called by the reloader to give the illusion that
the GC is precise. Meaning a class that will be unloaded is
immediately made invisible without waiting for it to be garbage collected.

This is easy to do up to Ruby 3.0 because `DescendantTracker` keeps
a map of all tracked classes.

However on 3.1 we need to use the inverse strategy, we keep a WeakMap
of all the classes we cleared, and we filter the return value of `descendants`
and `subclasses`.

Since `clear` is private API and is only used when reloading is enabled,
to reduce the performance impact in production mode, we entirely remove
this behavior when `config.cache_classes` is enabled.
2021-11-25 17:32:52 +01:00
Jean Boussier eea74ec211 AS::Callbacks specialize call templates for better performance
By doing so we avoid a lot of extra work.

```
            baseline:  4092604.4 i/s
          opt-method:   693204.7 i/s - 5.90x  (± 0.00) slower
              method:   614761.0 i/s - 6.66x  (± 0.00) slower
```

Baseline is calling `run_callbacks` with no callbacks registered.

Full benchmark: https://gist.github.com/casperisfine/837a7a665c6b232dadcf980d73694748
2021-11-25 14:03:46 +01:00
Espartaco Palma 2bf5e6618e
ActiveSupport::Cache, fix race conditions on test/cache - part V 2021-11-24 16:51:29 -08:00
Rafael Mendonça França 4799156cc3
Merge pull request #43704 from esparta/fix_race_conditions_test_cache_iv
ActiveSupport::Cache, fix race conditions on test/cache - part IV
2021-11-24 17:02:38 -05:00