Commit Graph

8563 Commits

Author SHA1 Message Date
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
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
Lee Quarella 65f350166a Remove overwriting test_order
Reverts a change from
2327ebfdc6
which can overwrite `test_order` that may have been manually set in
config. This can cause a situation where the user is depending on a
particular `test_order` but is unknowingly forced into another.
2021-03-31 11:50:08 -04:00
Jean Boussier d612542336
Merge pull request #41801 from Shopify/optimize-numeric-to-s
Optimize ActiveSupport::NumericWithFormat#to_s
2021-03-31 09:22:43 +02:00
Jean Boussier 31c20e248a Optimize ActiveSupport::NumericWithFormat#to_s
`case format when nil` is very efficient because it end up calling `NilClass === nil`
which pretty much translates to `nil.is_a?(NilClass)`.

On the other hand `format.nil?` benefit from a dedicated op code, so it's quite faster.

In this case `Integer#to_s` is much more often called without any arguments,
so it's worth optimizing for the most common case.

```ruby
class Integer
  alias_method :faster_to_s, :to_s
end
require 'active_support/all'
require 'benchmark/ips'

module FasterNumericWithFormat
  def faster_to_s(format = nil, options = nil)
    if format.nil?
      return super()
    end

    case format
    when Integer, String
      super(format)
    when :phone
      ActiveSupport::NumberHelper.number_to_phone(self, options || {})
    when :currency
      ActiveSupport::NumberHelper.number_to_currency(self, options || {})
    when :percentage
      ActiveSupport::NumberHelper.number_to_percentage(self, options || {})
    when :delimited
      ActiveSupport::NumberHelper.number_to_delimited(self, options || {})
    when :rounded
      ActiveSupport::NumberHelper.number_to_rounded(self, options || {})
    when :human
      ActiveSupport::NumberHelper.number_to_human(self, options || {})
    when :human_size
      ActiveSupport::NumberHelper.number_to_human_size(self, options || {})
    when Symbol
      super()
    else
      super(format)
    end
  end
end

Integer.prepend(FasterNumericWithFormat)

Benchmark.ips do |x|
  x.report('orig no-arg') { 42.to_s }
  x.report('fast no-arg') { 42.faster_to_s }
  x.compare!
end

Benchmark.ips do |x|
  x.report('orig :human') { 42.to_s(:human) }
  x.report('fast :human') { 42.faster_to_s(:human) }
  x.compare!
end
```

Ruby 2.7.2
```
Warming up --------------------------------------
         orig no-arg   567.569k i/100ms
         fast no-arg   692.636k i/100ms
Calculating -------------------------------------
         orig no-arg      5.709M (± 1.3%) i/s -     28.946M in   5.070660s
         fast no-arg      6.892M (± 0.7%) i/s -     34.632M in   5.024961s

Comparison:
         fast no-arg:  6892287.7 i/s
         orig no-arg:  5709450.0 i/s - 1.21x  (± 0.00) slower

Warming up --------------------------------------
         orig :human   575.000  i/100ms
         fast :human   619.000  i/100ms
Calculating -------------------------------------
         orig :human      6.176k (± 1.6%) i/s -     31.050k in   5.028656s
         fast :human      6.179k (± 1.8%) i/s -     30.950k in   5.010372s

Comparison:
         fast :human:     6179.1 i/s
         orig :human:     6176.3 i/s - same-ish: difference falls within error

```
2021-03-30 15:41:20 +02:00
John Hawthorn 3a770b2197 Fix LogSubscriber for buffered event w/ nil logger
LogSubscriber overrides start/finish to avoid instrumenting when its
logger is nil. In order to support buffered notification events, as used
by async queries, we need to apply a similar override to
LogSubscriber#publish_event.
2021-03-29 17:31:07 -07:00
Steve Laing d4186a76c8 Raise ArgumentError from TimeZone.iso8601 when invalid value can be parsed by Date._iso8601
Date._iso8601 will return a hash for some values eg. '12936' but this will not contain the expected :mon and :mday keys.
Check for these keys and raise an ArgumentError if they aren't present as this is consistent with other invalid input behaviour.
2021-03-26 09:10:45 +00:00
Eileen M. Uchitelle ad9e52066c
Merge pull request #41684 from ricardotk002/disable-parallel-testing
Disable parallel testing when running individual files
2021-03-23 09:06:57 -04:00
Jean Boussier a40fca290d Use triple-dot delegation in ForkTracker 2021-03-23 08:52:29 +01:00
Ryuta Kamizono 19fd39b672 `to_yaml` requires `require "yaml"`
https://buildkite.com/rails/rails/builds/75966#6b542bd0-82ce-4463-badf-7a68af7d3208/1055-1977
2021-03-23 08:51:39 +09:00
Ryuta Kamizono 3e71243b10 Parsing `type="yaml"` node requires `require "yaml"` 2021-03-23 08:45:46 +09:00
Ryuta Kamizono d7f5f4f97f Fix `test_from_trusted_xml_allows_symbol_and_yaml_types` failure
Caused by #41712.

https://buildkite.com/rails/rails/builds/75962#984c08aa-f57f-4f1c-ab31-7674fac12bbe/975-1397
2021-03-23 08:29:09 +09:00
Rafael Mendonça França 741099e995
Really make OrderedHash private to the framework
Related to 0dd7654032.
2021-03-22 22:13:23 +00:00
Ryuta Kamizono 1ef30c19b5
Merge pull request #41712 from okuramasafumi/remove-ordered-hash
Remove requires and references to OrderedHash
2021-03-22 22:01:26 +09:00
OKURA Masafumi 0dd7654032 Remove some references to OrderedHash
OrderedHash is deprecated but there are some requires and references
to OrderedHash, which might be confusing.
As described in
https://github.com/rails/rails/issues/22681#issuecomment-166059717
OrderedHash is internal only so references in the docs should be
removed.
2021-03-22 21:14:32 +09:00
Ryuta Kamizono 8c7883d3fc ✂️ [ci skip] 2021-03-22 04:46:11 +09:00
Ryuta Kamizono 1dcad65f80
Merge pull request #41707 from okuramasafumi/add-missing-require-to-hash_with_indifferent_access
Add missing require to hash_with_indifferent_access
2021-03-21 15:19:44 +09:00
OKURA Masafumi 8a56380c53
Add documentation to HashWithIndifferentAccess#except
https://api.rubyonrails.org/classes/ActiveSupport/HashWithIndifferentAccess.html#method-i-except
Currently HashWithIndifferentAccess#except has no documentation.
Since it's behavior is different from Hash#except, so it deserves
its own documentation.
2021-03-20 10:37:13 -04:00
OKURA Masafumi e4de1ca9b5 Add missing require to hash_with_indifferent_access
When requiring only "active_support/hash_with_indifferent_access",
calling `slice!` method on `HashWithIndifferentAccess` object
causes `NoMethodError`.
This is caused by `slice!` method calls `super` which is defined
in "active_support/core_ext/hash/slice" that' not required by this file.
Adding `require "active_support/core_ext/hash/slice"` to hwia
resolves this issue.

Note: since all tests `require_relative "abstract_unit"` that requires
"active_support/core_ext/hash/slice" eventually, it's pretty hard to
test method behavior without require.
2021-03-20 22:10:38 +09:00
Xavier Noria 6d38553b09 Removes the monkey-patch for Marshal.load
Marshal.load autoloads out of the box with Zeitwerk. See

    https://github.com/fxn/zeitwerk/blob/master/test/lib/zeitwerk/test_marshal.rb

for similar coverage.
2021-03-18 22:08:25 +01:00
Ricardo Díaz 2327ebfdc6 Disable parallel testing when running individual files
Setting up the parallel workers could be an overhead when running
individual files.

This patch disables that process in case the number of files to run
is less than one.

Results running a sample file:

Before:

```
actionpack $ bin/test test/controller/parameters/accessors_test.rb
Run options: --seed 48261

........................................................................

Finished in 0.211923s, 339.7460 runs/s, 552.0873 assertions/s.
72 runs, 117 assertions, 0 failures, 0 errors, 0 skips
```

After

```
actionpack $ bin/test test/controller/parameters/accessors_test.rb

Run options: --seed 5461

........................................................................

Finished in 0.008411s, 8560.2189 runs/s, 13910.3557 assertions/s.
72 runs, 117 assertions, 0 failures, 0 errors, 0 skips
```
2021-03-18 02:06:42 -05:00
Eileen M. Uchitelle 404a7f34c7
Merge pull request #41590 from Shopify/log-subscriber-publish
Forward sql.active_record notifications back into the calling thread
2021-03-10 16:16:36 -05:00
Ryuta Kamizono 55d913d34c
Merge pull request #41648 from alkesh26/fixed-incorrect-changelog-output
[ci skip] corrected the output of maximum in ActiveSupport changelog
2021-03-10 19:23:50 +09:00
Xavier Noria 482e081aaa Deletes AS::Dependencies.warnings_on_first_load 2021-03-10 07:55:29 +01:00
alkeshghorpade 40770b6878 corrected the output of maximum in ActiveSupport changelog 2021-03-10 10:57:53 +05:30
Xavier Noria dc7817cb42 Deletes logging from AS::Dependencies 2021-03-09 10:02:03 +01:00
Xavier Noria 43a7f68ae3 Deletes AS::Dependencies::Blamable
This is an internal class which is no longer needed.
2021-03-08 17:10:42 +01:00
Xavier Noria 3c90308b17 Deletes AS::Dependencies::ClassCache
This is an internal class which is no longer needed.
2021-03-08 07:54:28 +01:00
Xavier Noria 14d4edd7c3 Deletes AS::Dependencies::Reference
This is an internal class which is no longer needed.
2021-03-08 07:54:18 +01:00
Xavier Noria 0d523d8365 Drops support for classic mode
This starts a series of patches in which we drop classic mode. The final
result no longer has a const_missing callback, there is no hook/unhook,
and so on.

So, in this patch we remove the ability of configuring classic, but some
of the code that remains will be further refactored.
2021-03-08 05:30:11 +01:00
Ufuk Kayserilioglu 302fdb7677
Add missing require 2021-03-03 15:48:20 -05:00
Jean Boussier 091dc78f94 Forward sql.active_record notifications back into the calling thread
It is not uncommon for `sql.active_record` subscribers to rely on
thread local or fiber local state. For instance the `buffered-logger`
gem buffer the logs in a thread variable.

With the introduction of async queries, the `sql.active_record`
events can now be produced from a background thread and that break
some expectations.

This makes it hard for subscriber to map the event to the request
or job that scheduled it.

That is why I believe we should instead store the event and
publish it back on the calling thread when the results are
accessed.
2021-03-03 10:33:37 +01:00
Aaron Patterson d5ac941ddc
Remove special case filtering for Procs.
I'm writing this patch for two purposes:

1. I want to reduce the number of times `object_id` is called.  Calling
   `object_id` can have negative impacts on performance in Ruby 2.7+, so
   it would be nice to stop calling it.

2. I'm not sure why we're treating lambdas specially here.  It looks
   like we wanted to prevent people from skipping callbacks that were
   defined with a lambda, but I think that is silly.  If the user has a
   reference to a lambda, and they want to skip it, we should let them.

I think this cleans up some code, helps with performance, and is a more
intuitive interface.
2021-03-02 17:20:35 -08:00
Ryuta Kamizono 7b9cfde741 Fix `method_missing` delegation to not expand positional hash argument
Follow up to #41518, and similar to 3a85ced1a0.
2021-03-02 22:29:29 +09:00
Ryuta Kamizono 8cac41b841
Merge pull request #41522 from ghiculescu/file-store-no-path
Require a path for `config.cache_store = :file_store`
2021-02-24 01:53:55 +09:00
Alex Ghiculescu aedb2a7bae Require a for `config.cache_store = :file_store`
Currently if you do `config.cache_store = :file_store` in an initializer, your app will boot and the cache contents will be stored in a directory called `{}` in your project root. This is unlikely to be the intended outcome.

This PR raises an error if you call `config.cache_store = :file_store` without a path. The correct way to use the default cache path is `config.cache_store = :file_store, "#{config.root}/tmp/cache/"`.

To preserve the current behavior:

```ruby
config.cache_store = :file_store, "{}"
```

Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
2021-02-23 10:42:43 -06:00
Marcin Kolodziej 9d6b2b38fd Fix proxying keyword arguments for ActiveSupport::CurrentAttributes.
Also fixes `respond_to?` not working for methods that have not yet been delegated.
2021-02-22 17:42:48 +01:00
Rafael Mendonça França 37303ea499
Avoid having to store complex object in the default translation file
This make possible for applications to use the safe mode of yaml to
load the translations files.

Fixes #41459.
2021-02-18 06:25:56 +00:00
Ryuta Kamizono d049839e1f alias :without :excluding
Delegation by splat arguments will allocates an extra array.
2021-02-17 15:36:01 +09:00
Jonathan Hefner 167f5c8065 Fix inline code markup [ci-skip]
RDoc Markup does not support backticks the way Markdown does to mark up
inline code.  Additionally, `<tt>` must be used to mark up inline code
that includes spaces or certain punctuation characters (e.g. quotes).
2021-02-14 11:20:35 -06:00
Jonathan Hefner 5df979dd35 Test #maximum and #minimum with empty enumerable
Follow-up to #41404.

These tests will prevent regressions if we decide to change the
implementations of `maximum` or `minimum` in the future (for example,
calling `max_by` or `min_by` followed by `send`).
2021-02-12 16:20:51 -06:00
Ayrton De Craene 2526938b32 Calculate the minimum/maximum from an enumerable's extracted elements
```
payments = [Payment.new(5), Payment.new(15), Payment.new(10)]
payments.minimum(:price) # => 5
payments.maximum(:price) # => 20
```
2021-02-12 17:37:53 +01:00
Rafael França 06e8d5c29f
Merge pull request #41381 from movermeyer/allow_for_nil_addresses_from_dalli_store
Allow addresses to support `nil` values
2021-02-09 16:08:33 -05:00
Jean Boussier dd5b00cd6c Fix the underscore inflector optimization
It introduced a regression for strings with a group of exactly
two capital letters.
2021-02-09 16:37:45 +01:00
Michael Overmeyer 71963b1fc9 Allow addresses to support `nil` values
Users of `:dalli_store` may have been passing an explicit `nil` parameter for the servers:

```ruby
config.cache_store = :dalli_cache, nil, { expires_in: 2.hour, compress: true }
```

If they simply changed `:dalli_cache` and `:mem_cache_store`, the existing code passes `addresses = [nil]` to Dalli (instead of `nil`), which cause exceptions when people try to access the cache:

```
> Rails.cache.fetch('foo')
NoMethodError: undefined method `match' for nil:NilClass
```

This change allows users to continue passing the explicit `nil`, making migrations from `:dalli_store` to `:mem_cache_store` simpler.
2021-02-09 09:34:10 -05:00
Ryuta Kamizono 7b680baea2 Remove `require "active_support/core_ext/symbol/starts_ends_with"`
Ruby 2.7 has native `Symbol#start_with?` and `Symbol#end_with?`.
2021-02-09 22:31:09 +09:00
Rafael Mendonça França 249232f659
Fix warning with Ruby 2.7 on Time.at with keyword arguments
Closes #41375
2021-02-09 03:51:54 +00:00
Rafael Mendonça França 5d10e8e343
Fix the cache key to remove reference to md5 2021-02-09 00:28:19 +00:00
fatkodima d13937bab5 Handle nil key for MemCacheStore#normalize_key 2021-02-09 00:56:23 +02:00