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
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.
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.
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.
* 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`
`[].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 `[[]]`.
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.
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
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.
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.
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.
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.
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