Commit Graph

9180 Commits

Author SHA1 Message Date
Aaron Patterson f985028bcc
Stop gap solution for long output on test cases
This patch just changes the inspect method on test case instances.
Seeing test instance internals probably isn't helpful when an exception
is raised (for example a `NoMethodError`).

This isn't as good as #45122, but should fix #45121
2022-08-24 09:54:02 -07:00
Yusuke Endoh 3beb2aff3b Use error_highlight gem to locate the columns where an error was raised
This change incorporates to Rails a feature called error_highlight that
has been available since Ruby 3.1. This allow Rails' error report screen
to display the fine-grained location where an error occurred (not only a
line number but also beginning and end column numbers of the code
fragment).

For ErrorHighlight, see https://bugs.ruby-lang.org/issues/17930 in
detail.

To use error_highlight, ExceptionWrapper now prefers
`Exception#backtrace_locations` (since Ruby 2.1), which returns an array
of `Thread::Backtrace::Location`s, instead of `Exception#backtrace`.
This is because error_highlight requires `Thread::Backtrace::Location`
to locate the column where an error was raised.

Co-Authored-By: John Hawthorn <john@hawthorn.email>
Co-Authored-By: Jean Boussier <jean.boussier@gmail.com>
2022-08-24 00:28:50 +09:00
Akshay Birajdar 8e6d1f55e2 Remove unnecessary class_eval from log_subscriber.rb 2022-08-22 20:00:58 +05:30
Jean Boussier 2418939007
Merge pull request #45796 from Shopify/log-subscriber-silenced
Optimize AS::LogSubscriber
2022-08-22 10:43:49 +02:00
Jean Boussier 341d627a57 RedisCacheStore: don't pass url if it's nil
In 5.0 it will prevent `$REDIS_URL` from being used.
2022-08-22 09:01:27 +02:00
Jean Boussier adb5028ff8 RedisCacheStore: update test suite for redis-rb 5.0
No real code change, only our stubs need to be changed.
2022-08-22 09:01:27 +02:00
Jean Boussier f2ab66da73 Stop testing hiredis
The driver being used is an implementation detail of `redis-rb`.
If somehow something break on one driver but not the other, it should
be reported to redis-rb and fixed there.

Also `redis-rb` `5.0` has a totally new client and hiredis binding
so all this code no longer works with redis-rb 5.0.
2022-08-22 09:01:27 +02:00
Guillermo Iguaran 3d84e1298b
Merge pull request #45842 from trevorturk/validate-expires-at
Log a warning if ActiveSupport::Cache is given an expiration in the past
2022-08-18 15:32:13 -07:00
Trevor Turk 7eeb4af7c8 Log a warning if ActiveSupport::Cache is given an expiration in the past 2022-08-18 17:04:21 -05:00
Ian C. Anderson d5695001f1 `xml_name_escape`: Optimize the common case
This came out of a conversation I had with @jhawthorn about how we could further
optimize the performance of `xml_name_escape`, which is a hot path for view
rendering.

This adds an early return to the method that improves the "valid name" case
performance by 2-3x, without adding any measurable overhead to the "invalid
case" (according to the benchmark below).

This also updates the constant names to reflect the fact that the regular
expressions are matching characters that are _not_ valid.

Benchmark results:

```
============================ Common tag name short =============================

Warming up --------------------------------------
     xml_name_escape   159.671k i/100ms
fast_xml_name_escape   343.621k i/100ms
one_regex_xml_name_escape
                       353.869k i/100ms
Calculating -------------------------------------
     xml_name_escape      1.582M (± 3.8%) i/s -      7.984M in   5.055645s
fast_xml_name_escape      3.341M (± 4.7%) i/s -     16.837M in   5.051945s
one_regex_xml_name_escape
                          3.489M (± 4.9%) i/s -     17.693M in   5.085095s

Comparison:
one_regex_xml_name_escape:  3488934.6 i/s
fast_xml_name_escape:  3341149.3 i/s - same-ish: difference falls within error
     xml_name_escape:  1581604.8 i/s - 2.21x  (± 0.00) slower

============================= Common tag name long =============================

Warming up --------------------------------------
     xml_name_escape    76.117k i/100ms
fast_xml_name_escape   266.879k i/100ms
one_regex_xml_name_escape
                       257.459k i/100ms
Calculating -------------------------------------
     xml_name_escape    826.616k (± 4.3%) i/s -      4.186M in   5.074708s
fast_xml_name_escape      2.751M (± 5.0%) i/s -     13.878M in   5.060281s
one_regex_xml_name_escape
                          2.545M (± 5.6%) i/s -     12.873M in   5.077729s

Comparison:
fast_xml_name_escape:  2751129.4 i/s
one_regex_xml_name_escape:  2544673.8 i/s - same-ish: difference falls within error
     xml_name_escape:   826616.2 i/s - 3.33x  (± 0.00) slower

=============================== Custom tag name ================================

Warming up --------------------------------------
     xml_name_escape    78.065k i/100ms
fast_xml_name_escape   242.412k i/100ms
one_regex_xml_name_escape
                       231.727k i/100ms
Calculating -------------------------------------
     xml_name_escape    767.433k (± 6.5%) i/s -      3.825M in   5.012273s
fast_xml_name_escape      2.463M (± 4.3%) i/s -     12.363M in   5.030648s
one_regex_xml_name_escape
                          2.239M (± 6.5%) i/s -     11.355M in   5.095769s

Comparison:
fast_xml_name_escape:  2462694.6 i/s
one_regex_xml_name_escape:  2238947.7 i/s - same-ish: difference falls within error
     xml_name_escape:   767432.9 i/s - 3.21x  (± 0.00) slower

========================== Custom tag name non-ascii ===========================

Warming up --------------------------------------
     xml_name_escape    66.959k i/100ms
fast_xml_name_escape    63.131k i/100ms
one_regex_xml_name_escape
                       206.018k i/100ms
Calculating -------------------------------------
     xml_name_escape    686.496k (± 4.9%) i/s -      3.482M in   5.085224s
fast_xml_name_escape    643.266k (± 4.5%) i/s -      3.220M in   5.016957s
one_regex_xml_name_escape
                          2.010M (± 4.8%) i/s -     10.095M in   5.034582s

Comparison:
one_regex_xml_name_escape:  2010415.6 i/s
     xml_name_escape:   686496.1 i/s - 2.93x  (± 0.00) slower
fast_xml_name_escape:   643266.0 i/s - 3.13x  (± 0.00) slower

================================ Bad tag name 1 ================================

Warming up --------------------------------------
     xml_name_escape    40.491k i/100ms
fast_xml_name_escape    40.465k i/100ms
one_regex_xml_name_escape
                        38.244k i/100ms
Calculating -------------------------------------
     xml_name_escape    393.998k (± 6.7%) i/s -      1.984M in   5.062913s
fast_xml_name_escape    386.906k (± 5.2%) i/s -      1.942M in   5.035445s
one_regex_xml_name_escape
                        377.664k (± 6.6%) i/s -      1.912M in   5.088602s

Comparison:
     xml_name_escape:   393998.2 i/s
fast_xml_name_escape:   386906.4 i/s - same-ish: difference falls within error
one_regex_xml_name_escape:   377663.7 i/s - same-ish: difference falls within error

================================ Bad tag name 2 ================================

Warming up --------------------------------------
     xml_name_escape    15.627k i/100ms
fast_xml_name_escape    15.165k i/100ms
one_regex_xml_name_escape
                        16.028k i/100ms
Calculating -------------------------------------
     xml_name_escape    161.988k (± 5.5%) i/s -    812.604k in   5.032083s
fast_xml_name_escape    161.438k (± 5.7%) i/s -    818.910k in   5.090467s
one_regex_xml_name_escape
                        160.224k (± 5.1%) i/s -    801.400k in   5.016219s

Comparison:
     xml_name_escape:   161987.9 i/s
fast_xml_name_escape:   161437.6 i/s - same-ish: difference falls within error
one_regex_xml_name_escape:   160224.2 i/s - same-ish: difference falls within error
```

Benchmark code:

```ruby

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "rails", github: "rails/rails", branch: "main"
  gem "benchmark-ips"
end

require "active_support"
require "active_support/core_ext/string/output_safety"

class ERB
  module Util
    TAG_NAME_COMMON_CASE = /\A[a-z][a-z\-]*\z/

    def fast_xml_name_escape(name)
      name = name.to_s
      return "" if name.blank?
      return name if name.match?(TAG_NAME_COMMON_CASE)

      starting_char = name[0]
      starting_char.gsub!(TAG_NAME_START_REGEXP, TAG_NAME_REPLACEMENT_CHAR)

      return starting_char if name.size == 1

      following_chars = name[1..-1]
      following_chars.gsub!(TAG_NAME_FOLLOWING_REGEXP, TAG_NAME_REPLACEMENT_CHAR)

      starting_char << following_chars
    end
    module_function :fast_xml_name_escape

    TAG_NAME_FOLLOWING_REGEXP_SET = "#{TAG_NAME_START_REGEXP_SET}\-.0-9\u{B7}\u{0300}-\u{036F}\u{203F}-\u{2040}"
    SAFE_XML_TAG_NAME_REGEXP = /\A[#{TAG_NAME_START_REGEXP_SET}][#{TAG_NAME_FOLLOWING_REGEXP_SET}]*\z/

    def one_regex_xml_name_escape(name)
      name = name.to_s
      return "" if name.blank?
      return name if name.match?(SAFE_XML_TAG_NAME_REGEXP)

      starting_char = name[0]
      starting_char.gsub!(TAG_NAME_START_REGEXP, TAG_NAME_REPLACEMENT_CHAR)

      return starting_char if name.size == 1

      following_chars = name[1..-1]
      following_chars.gsub!(TAG_NAME_FOLLOWING_REGEXP, TAG_NAME_REPLACEMENT_CHAR)

      starting_char << following_chars
    end
    module_function :one_regex_xml_name_escape
  end
end

SCENARIOS = {
  "Common tag name short" => "p",
  "Common tag name long"  => "textarea",
  "Custom tag name"       => "super-custom",
  "Custom tag name non-ascii" => "süper-custom",
  "Bad tag name 1"        => "1abc",
  "Bad tag name 2"        => "1 < 2 & 3",
}

SCENARIOS.each_pair do |name, value|
  puts
  puts " #{name} ".center(80, "=")
  puts

  Benchmark.ips do |x|
    x.report("xml_name_escape")      { ERB::Util.xml_name_escape(value) }
    x.report("fast_xml_name_escape") { ERB::Util.fast_xml_name_escape(value) }
    x.report("one_regex_xml_name_escape") { ERB::Util.one_regex_xml_name_escape(value) }
    x.compare!
  end
end
```
2022-08-18 20:21:56 +00:00
Ian C. Anderson b8191db909 Reduce Striing allocations in `xml_name_escape`
When working in a large rails app, I noticed in a flamegraph of a particular request that ~68ms was spent in the `xml_name_escape` method. I also ran an allocation tracer, which showed this method at the top of the list for String allocations.

This patch updates this method to avoid 3 String allocations:
- 2 allocations saved by using gsub! instead of gsub
- 1 allocation saved by concatenating to an existing string instead of allocating a new output string

For a rough benchmark in our rails app, I wrote a test with an allocation tracer around rendering a small view component.
- 244 String allocations before this change
- 228 String allocations from switching to gsub!
- 220 String allocations with this full patch

A ~10% reduction in String allocations in a real-world example seemed like a good justification for this small change.
2022-08-16 20:27:25 +00:00
Jean Boussier bd19d1baf1 Optimize AS::LogSubscriber
The various LogSubscriber subclasses tend to subscribe to events
but then end up doing nothing if the log level is high enough.

But even if we end up not logging, we have to go through the
entire notification path, record timing etc.

By allowing subscribers to dynamically bail out early, we can
save a lot of work if all subscribers are silenced.
2022-08-12 09:58:17 +02:00
Jonathan Hefner e8f189b1cb Improve ActiveSupport::ErrorReporter API doc [ci-skip]
This moves some of the documentation from the `ErrorReporter` class
directly to the `handle` and `record` methods, and fleshes those out.
This also tweaks the documentation of the other `ErrorReporter` methods.
2022-08-10 19:08:01 -05:00
Shalvah dd80ab07a8 Update ErrorSubscriber signature
Document `severity` argument.

Change union types syntax; add docs

Trim line

Fix trailing whitespace

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2022-08-10 19:04:55 -05:00
Rafael Mendonça França b8868d6498
Merge pull request #44753 from ghousemohamed/extend-reserved-keywords-list-in-module-delegation
Extends ruby reserved keywords list in Module ext in Active Support
2022-08-09 16:20:45 -03:00
Jonathan Hefner 7563be4d97 Document AS::Cache::MemCacheStore#write options [ci-skip] 2022-08-05 21:36:19 -05:00
Jonathan Hefner 7e884e2996 Document AS::Cache::Store#initialize options [ci-skip] 2022-08-05 21:36:19 -05:00
Jonathan Hefner a95438caff Document AS::Cache::Store#read options [ci-skip] 2022-08-05 21:36:19 -05:00
Jonathan Hefner fc7225afc7 Rewrite AS::Cache::Store#fetch options doc as list [ci-skip] 2022-08-05 21:36:18 -05:00
Jonathan Hefner b55f079f9d Consolidate AS::Cache::Store#write documentation [ci-skip] 2022-08-05 21:36:18 -05:00
Jonathan Hefner dce8b7fe6b Improve rescue_from example [ci-skip] 2022-08-05 21:36:18 -05:00
Jonathan Hefner 32c169d014 Linkify code references [ci-skip] 2022-08-05 21:36:18 -05:00
Jonathan Hefner b13107fe5e Fix typos [ci-skip] 2022-08-05 21:36:18 -05:00
fatkodima b0061a30a0 Improve failure safety for `RedisCacheStore#delete_multi`
For redis cache store, running `Rails.cache.delete_multi(["foo", "bar"])`
will lead to an error when redis is down. Other existing cache store methods
already implement failure safety.
2022-08-04 18:53:10 +03:00
fatkodima 813b58d8f9 Fix flaky tests for RedisCacheStore 2022-08-02 15:39:06 +03:00
fatkodima 6dad6e7604 Fix `Cache::NullStore` with local caching for repeated reads 2022-08-02 03:18:35 +03:00
Jean Boussier e7bc2cb16f
Merge pull request #45717 from stevecrozz/tagged_logging_formatter_method_persistence
TaggedLogging preserves formatter methods
2022-08-01 19:27:12 +02:00
fatkodima e35eb0f779 Optimize increment and decrement for `RedisCacheStore` 2022-08-01 17:23:53 +03:00
Jean Boussier f9fce850da RedisCacheStore: get rid of the Redis::Distributed check
Instead we lazily check for pipelining support. `Redis::Distributed`
immediately raise when `pipelined` is called.

Also instead of using `mset` we use a pipelined. The performance
difference is extremly minimal, but it allows us to re-use `write_entry`
hence more shared code and we can speed up `write_multi` with an
expiry.
2022-08-01 14:33:29 +02:00
Jean Boussier 5aa9d16969 RedisCacheStore: avoid monkey patching redis
ConnectionPool#with is aliased as #then which is equivalent
to Object#then since Ruby 2.5. So if we use that we don't need
to monkey patch anything.
2022-08-01 12:19:14 +02:00
Jean Boussier c617b8f8fd RedisCacheStore: remove unused mget_capable? flag
Ever since its introduction it was never set to false.
2022-08-01 12:00:12 +02:00
Stephen Crosby 77209cc017
TaggedLogging preserves formatter methods
TaggedLogging preserves any methods that exist on the formatter's
singleton class.
2022-07-31 13:46:07 -07:00
Jonathan Hefner 772c462738 Save encrypted config even if YAML is invalid
In #30893, the `credentials:edit` command was changed to prevent saving
invalid YAML:

  ```yaml
  # some_invalid_yaml.yml
  secret_key_base: ...
  - new_key: new value
  ```

  ```console
  $ EDITOR='cp some_invalid_yaml.yml' bin/rails credentials:edit
  ruby-3.1.2/lib/ruby/3.1.0/psych.rb:455:in `parse': (<unknown>): did not find expected key while parsing a block mapping at line 3 column 1 (Psych::SyntaxError)

  $ bin/rails credentials:show
  secret_key_base: ...
  ```

However, throwing away user input is not ideal.  Such behavior can be
particularly troublesome when copying secrets from ephemeral sources.

This commit changes the `credentials:edit` command to always save user
input, and display a helpful warning when saving invalid YAML:

  ```console
  $ EDITOR='cp some_invalid_yaml.yml' bin/rails credentials:edit
  File encrypted and saved.
  WARNING: Invalid YAML in '/path/to/app/config/credentials.yml.enc'.

    (/path/to/app/config/credentials.yml.enc): did not find expected key while parsing a block mapping at line 3 column 1

  Your application will not be able to load 'config/credentials.yml.enc' until the error has been fixed.

  $ bin/rails credentials:show
  # some_invalid_yaml.yml
  secret_key_base: ...
  - new_key: new value
  ```

This commit also applies the same fix to the `encrypted:edit` command.
2022-07-28 16:37:18 -05:00
Jonathan Hefner 1740b1f2cb Generate master.key even when require_master_key
Prior to this commit, if `config.require_master_key` was set to true in
`config/application.rb`, the `credentials:edit` command could not
automatically generate a master key file:

  ```ruby
  # In config/application.rb
  config.require_master_key = true
  ```

  ```console
  # No previously existing credentials
  $ rm config/master.key config/credentials.yml.enc
  ```

  ```console
  $ bin/rails credentials:edit
  activesupport/lib/active_support/encrypted_file.rb:118:in `handle_missing_key': Missing encryption key to decrypt file with. Ask your team for your master key and write it to config/master.key or put it in the ENV['RAILS_MASTER_KEY']. (ActiveSupport::EncryptedFile::MissingKeyError)
  ```

This commit adds a `EncryptedFile#key?` method that can be used to check
for the existence of a key without raising `MissingKeyError`, and the
`credentials:edit` command now uses this method:

  ```console
  $ bin/rails credentials:edit
  Adding config/master.key to store the encryption key: ...

  Save this in a password manager your team can access.

  If you lose the key, no one, including you, can access anything encrypted with it.

        create  config/master.key
  ```

This commit also applies the same fix to the `encrypted:edit` command.
2022-07-27 11:22:41 -05:00
Jonathan Hefner 2af4b98870 Make EncryptedFile more memoization-friendly
Prior to this commit, `EncryptedFile` would internally memoize when a
key file was non-existent.  This meant that a key file generated after
checking `encrypted_file.key.nil?` would not be recognized, unless a new
`EncryptedFile` instance was used.  (Though setting the key in a
designated environment variable instead would entirely bypass this
memoization.)

This commit changes `EncryptedFile` to only memoize when the key file
has been read.  Consequently, this commit memoizes the `EncryptedFile`
(or, specifically, `EncryptedConfiguration`) instance used by
`CredentialsCommand`.

This commit also adds more test coverage around key file generation for
`CredentialsCommand`.
2022-07-25 11:57:04 -05:00
Jonathan Hefner 3d0686a9f6 Document ActiveSupport::EncryptedFile#key [ci-skip] 2022-07-24 18:43:19 -05:00
Jonathan Hefner 789a3648f3
Merge pull request #45619 from pbstriker38/add_skip_nil_to_fetch_multi
Add `skip_nil:` support to `ActiveSupport::Cache::Store#fetch_multi`
2022-07-21 10:33:34 -05:00
Jonathan Hefner aced3bb07b
Merge pull request #45569 from whyinzoo/whyinzoo-update-docs-ActiveSupport--Notification-monotonic-subscribe-for-pr
Add docs for ActiveSupport::Notifications.monotonic_subscribe [ci-skip]
2022-07-21 10:24:06 -05:00
Ryan Zhou e3de7872b1 better docs for ActiveSupport::Notifications.monotonic_subscribe 2022-07-21 03:20:33 +00:00
Daniel Alfaro 1344031d7e Add `skip_nil:` support to `ActiveSupport::Cache::Store#fetch_multi` 2022-07-20 17:02:25 -05:00
John Hawthorn b5a758db1b
Avoid checking defined?(@html_safe) (#45620)
We should not need to check defined? here because we are only interested
in whether @html_safe is truthy or falsy.

We can  use an aliased attr_reader to make this even faster by skipping
both method dispatch.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2022-07-19 15:16:21 -07:00
Jonathan Hefner 4e9fee9629
Merge pull request #45570 from whyinzoo/whyinzoo-update-docs-ActiveSupport--EncryptedFile-read-for-pr
Add docs for ActiveSupport::EncryptedFile#read [ci-skip]
2022-07-18 11:16:44 -05:00
Ryan Zhou d64367e765 better docs for ActiveSupport::EncryptedFile#read 2022-07-16 04:04:42 +00:00
Hartley McGuire 81c5c9971a
Fix extra changelog entry added in 959d46e (#45604)
The :urlsafe option was renamed to :url_safe in 7094d0f and the correct
entry is still below
2022-07-14 17:03:07 -07:00
matt swanson 959d46ef87
Add `quarter` method to date/time (#45009)
Co-authored-by: David Heinemeier Hansson <david@hey.com>
2022-07-14 16:43:52 -07:00
Hartley McGuire 5458571254
Add missing CHANGELOG authors
Ref 44a2971
Ref 9f0b8eb
2022-07-11 01:43:32 -04:00
Jonathan Hefner 7094d0fc43 Rename :urlsafe option to :url_safe
Although Ruby provides `Base64.urlsafe_encode64` and
`Base64.urlsafe_decode64` methods, the technical term is "URL-safe",
with "URL" and "safe" as separate words.

For better readability, this commit renames the `:urlsafe` option for
`MessageEncryptor` and `MessageVerifier` to `:url_safe`.
2022-07-08 15:36:24 -05:00
fatkodima faacccdb75 Clear cache in MemCacheStore tests 2022-07-07 00:25:15 +03:00
Ryo Nakamura 6f9bb2cc0f Fix NoMethodError on custom ActiveSupport::Deprecation behavior
with some additional changes made later:

1. Flip the condition for backward compatibility
   Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>

2. Improve custom behavior test
   Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>

3. Fix indentation
2022-07-06 06:41:41 +09:00
Jonathan Hefner 50402fc2ce
Merge pull request #45473 from jonathanhefner/message_encryptor-urlsafe-option
Support `:urlsafe` option for `MessageEncryptor`
2022-06-29 16:21:12 -05:00
Jonathan Hefner d9823326e8 Support :urlsafe option for MessageEncryptor
This adds a `:urlsafe` option to the `MessageEncryptor` constructor.
When enabled, this option ensures that messages use a URL-safe encoding.
This matches the `MessageVerifier` `:urlsafe` option added in #45419.
2022-06-29 16:00:16 -05:00
Jonathan Hefner 815f5baf14 Refactor message parts logic in MessageEncryptor
Follow-up to #43924.

This commit refactors the logic around assembling and extracting the
parts of a message (namely: the encrypted data, the IV, and the auth
tag).  It also provides a small but reproducible performance increase
for a roundtrip.

Benchmark:

```ruby
require "benchmark/ips"
require "active_support/message_encryptor"

DATA = "x" * 100
ENCRYPTOR = ActiveSupport::MessageEncryptor.new(SecureRandom.random_bytes(32))

Benchmark.ips do |x|
  x.report("roundtrip") do
    ENCRYPTOR.decrypt_and_verify(ENCRYPTOR.encrypt_and_sign(DATA))
  end
end
```

Before:

```
Warming up --------------------------------------
           roundtrip     1.342k i/100ms
Calculating -------------------------------------
           roundtrip     13.525k (± 1.5%) i/s -     68.442k in   5.061532s
```

After:

```
Warming up --------------------------------------
           roundtrip     1.409k i/100ms
Calculating -------------------------------------
           roundtrip     14.125k (± 1.4%) i/s -     71.859k in   5.088419s
```
2022-06-28 14:28:47 -05:00
Jonathan Hefner 73ef37902e Replace MessageVerifier :urlsafe option tests
The `test_urlsafe` test could not fail when `urlsafe: false` because the
serialized input data did not contain a bit sequence that would encode
to a non-URL-safe character.  The `test_no_padding` *could* fail when
`urlsafe: false`, except when the default serializer uses JSON, because
the serialized input data would be a multiple of 3 bytes, thus not
requiring any padding.

This commit replaces those tests with a falsifiable test using a
carefully chosen input string.
2022-06-28 14:19:28 -05:00
Hartley McGuire 31d2468a25
Document that load hooks run if already triggered
After first learning of this in c2a3ff0 and later discussion about cross
component dependencies, it makes sense to document it explicitly.
2022-06-23 17:34:41 -04:00
eileencodes 9766eb4a83
Fix tests for minitest 5.16
In minitest/minitest@6e06ac9 minitest changed such that it now accepts
`kwargs` instead of requiring kwargs to be shoved into the args array.
This is a good change but required some updates to our test code to get
the new version of minitest passing.

Changes are as follows:

1) Lock minitest to 5.15 for Ruby 2.7. We don't love this change but
it's pretty difficult to get 2.7 and 3.0 to play nicely together with
the new kwargs changes. Dropping 2.7 support isn't an option right
now for Rails. This is safe because all of the code changes here are
internal methods to Rails like assert_called_with. Applications
shouldn't be consuming them as they are no-doc'd.
2) Update the `assert_called_with` method to take any kwargs but also
the returns kwarg.
3) Update callers of `assert_called_with` to move the kwargs outside the
args array.
4) Update the message from marshaled exceptions. In 5.16 the exception
message is "result not reported" instead of "Wrapped undumpable
exception".

Co-authored-by: Matthew Draper <matthew@trebex.net>
2022-06-23 08:32:11 -04:00
Jean Boussier 2f5dcb7255
Merge pull request #45424 from shouichi/remove-padding-from-urlsafe-message-verifier
Fix urlsafe MessageVerifier not to include padding
2022-06-22 23:55:23 +02:00
Jonathan Hefner 1003e974ed Tweak MessageVerifier :urlsafe option doc [ci-skip]
Follow-up to #45425.

This fixes a few typos, and slightly adjusts the wording.
2022-06-22 11:21:10 -05:00
Shouichi Kamiya 3234863a83 Document urlsafe option of MessageVerifier
Also clarify that MessageVerifier generates non-urlsafe strings by
default.

[skip ci]
2022-06-22 15:47:21 +09:00
Shouichi Kamiya 08afa160a5 Fix urlsafe MessageVerifier not to include padding
urlsafe option was introduced to MessageVerifier in
09c3f36a96 but it can generate strings
containing padding character ("=") which is not urlsafe.

Fix not to pad when base64 encode.
2022-06-22 15:15:02 +09:00
Shouichi Kamiya 09c3f36a96 Add urlsafe option to MessageVerifier initializer
MessageVerifier uses Base64.strict_encode64 and generated strings are
not urlsafe. Though the goal is to make MessageVerifier generated
strings urlsafe, We can not simply switch to Base64.urlsafe_encode64
because it will be a breaking change. Thus, as a first step, urlsafe
option is added to the MessageVerifier initializer.
2022-06-21 21:40:35 +09:00
John Crepezzi df0de681dc Remove the multi-call form of assert_called_with
The `assert_called_with` helper allows passing a multi-dimensional array to
mock multiple calls to the same method for a given block. This works
fine now, but when adding support for real kwargs arguments to line up with
recent upgrades in Minitest, this approach is no longer workable because
we can't pass multiple sets of differing kwargs.

Rather than complicated this method further, this commit removes the
multi-call form of `assert_called_with` and modifies the tests that
currently make use of that functionality to just use the underlying
`Minitest::Mock` calls.

Co-authored-by: Eileen M. Uchitelle <eileencodes@gmail.com>
2022-06-16 11:13:57 -04:00
Asherah Connor ec34400abb
Behaviour constant deprecation fix (#45367)
* Add failing test for Behaviour deprecated alias

* Correct DeprecatedConstantProxy use

* DeprecatedConstantProxy docs indicate "full" constant names
2022-06-15 10:21:17 -07:00
Jean Boussier 29425c1997
Merge pull request #45318 from mihaic195/fix/local-cache-method-signature
Fix local cache method signature
2022-06-13 20:33:17 +02:00
Jean Boussier 115be62709 Wrap rails runner in executor
The main reason is to automatically report uncaught exceptions
since `rails runner` is often used for cron tasks and such.
2022-06-10 14:16:49 +02:00
mihaic195 cd650611ea
Fix local cache method signature 2022-06-10 11:40:19 +01:00
Jean Boussier 34fb4c4f9a
Merge pull request #45245 from akostadinov/cache_hash
MemCacheStore shorten keys properly
2022-06-09 14:21:06 +02:00
Aleksandar N. Kostadinov 7dd149477d
MemCacheStore shorten keys properly
The logic for shortening long keys in MemCacheStore
is broken since the time it stopped using MD5 checksumming.

Memcached supports keys up to 250 chars length. The reason
things worked I believe is because the underlying Dalli
library is doing it's own key shortening. Which uses its own
hashing function and in fact limits keys to 249 chars, see
petergoldstein/dalli@74b2625f11

This patch in a similar way properly truncates keys to 250
characters and avoids double hashing on Dalli side. Also
makes key name more predictable and independent from the
underlying Dalli version.
2022-06-09 15:06:06 +03:00
Jean Boussier 82095de39f
Merge pull request #45293 from ghiculescu/cache_format_version_setting
Correctly read the `cache_format_version` setting on boot
2022-06-08 20:55:15 +02:00
Alex Ghiculescu 08352a2478 Correctly read the `cache_format_version` setting on boot
Fixes https://github.com/rails/rails/issues/45289
2022-06-08 13:21:29 -05:00
fatkodima 799b5c1df4 Enable connection pooling by default for MemCacheStore and `RedisCacheStore` 2022-06-07 11:40:17 +03:00
John Hawthorn 6a2393ff6b Fix includes of deprecation proxy modules
Previously, including/prepending/extending one of these deprecated
constants would silently succeed, since it is a module.

This adds a defintion for append_features/prepend_features/extended so
that it can forward the inclusion onto the target module.
2022-06-02 18:13:31 -07:00
John Hawthorn dbf2edb7f2 Make Notifier::Fanout faster and safer
This commit aims to improve ActiveSupport::Notifications::Fanout. There
are three main goals here: backwards compatibility, safety, and
performance.

* Backwards compatibility

This ActiveSupport::Notifications is an old and well used interface.
Over time it has collected a lot of features and flexibility, much of
which I suspect is not used anywhere by anyone, but it is hard to know
specifics and we would at minimum need a deprecation cycle.

For this reason this aims to fully maintain compatibility. This includes
both the ability to use an alternate notification implementation instead
of Fanout, the signatures received by all types of listeners, and the
interface used on the Instrumenter and Fanout itself (including the
sometimes problematic start/finish).

* Safety

There have been issues (both recent and past) with the "timestacks"
becoming invalid, particularly when subscribing and unsubscribing within
events. This is an issue when topics are subscribed/unsubscribed to
while they are in flight.

The previous implementation would record a separate timestamp or event
object for each listener in a thread local stack. This meant that it was
essential that the listeners to start and finish were identical.

This issue is avoided by passing the listeners used to `start` the event
to `finish` (`finish_with_state` in the Instrumenter), to ensure they
are the same set in `start`/`finish`.

This commit further avoids this issue. Instead of pushing individual
times onto a stack, we now push a single object, `Handle`, onto the
stack for an event. This object holds all the subscribers (recorded at
start time) and all their associated data. This means that as long as
start/stop calls are not interleaved.

This commit also exposes `build_handle` as a public interface. This
returns the Handle object which can have start/stop called at any time
and any order safely. The one reservation I have with making this public
is that existing "evented" listeners (those receiving start/stop) may
not be ready for that (ex. if they maintain an internal thread-local
stack).

* Performance

This aims to be faster and make fewer allocations then the existing
implementation.

For time-based and event-object-based listeners, the previous
implementation created a separate object for each listener, pushing
and popping it on a thread-local stack. This is slower both because we
need to access the thread local repeatedly (hash lookups) and because
we're allocating duplicate objects.

The new implementation works by grouping similar types of listeners
together and shares either the `Event` or start/stop times between all
of them. The grouping was done so that we didn't need to allocate Events
or Times for topics which did have a listener of that type.

This implementation is significantly faster for all cases, except for
evented, which is slower.

For topics with 10 subscriptions:

*main*:

               timed     66.739k (± 2.5%) i/s -    338.800k in   5.079883s
     timed_monotonic    138.265k (± 0.6%) i/s -    699.261k in   5.057575s
        event_object     48.650k (± 0.2%) i/s -    244.250k in   5.020614s
             evented    366.559k (± 1.0%) i/s -      1.851M in   5.049727s
        unsubscribed      3.696M (± 0.5%) i/s -     18.497M in   5.005335s

*This branch*:

               timed    259.031k (± 0.6%) i/s -      1.302M in   5.025612s
     timed_monotonic    327.439k (± 1.7%) i/s -      1.665M in   5.086815s
        event_object    228.991k (± 0.3%) i/s -      1.164M in   5.083539s
             evented    296.057k (± 0.3%) i/s -      1.501M in   5.070315s
        unsubscribed      3.670M (± 0.3%) i/s -     18.376M in   5.007095s

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
Co-authored-by: Theo Julienne <theojulienne@github.com>
2022-06-01 18:54:44 -07:00
Mike Dalessio 5f8f6764d8
Strings returned from `strip_tags` are correctly tagged `html_safe?`
Because these strings contain no HTML elements and the basic entities
are escaped, they are safe to be included as-is as PCDATA in HTML
content. Tagging them as html-safe avoids double-escaping entities
when being concatenated to a SafeBuffer during rendering.

Fixes https://github.com/rails/rails-html-sanitizer/issues/124
2022-05-31 10:02:07 -04:00
Dirceu Pereira Tiegs 33411ad2b3
Fix with_options bug when first argument is a Proc
An ArgumentError was being raised when methods were called with (proc,
options) inside a with_options block:

    def my_method(arg1, **kwargs)
      [arg1, kwargs]
    end

    # this would raise instead of merging options
    with_options(hello: "world") do
      my_method(proc {}, {fizz: "buzz"})
    end

Fixes #45183
2022-05-28 16:07:34 -04:00
Gannon McGibbon 90c0bde47c Rename behaviour to behavior in test case names 2022-05-26 17:14:18 -04:00
Jean Boussier d4a660f1cb
Merge pull request #45174 from fatkodima/fetch_multi-force
Add `force:` support to `ActiveSupport::Cache::Store#fetch_multi`
2022-05-25 10:02:48 -04:00
Matthew Draper b5d12eaee8
Merge pull request #45061 from matthewd/assert-on-main-thread
Bubble assertion failures back to the main thread
2022-05-25 20:33:04 +09:30
fatkodima 358556b971 Add `force:` support to `ActiveSupport::Cache::Store#fetch_multi` 2022-05-25 03:19:12 +03:00
Ajay Sharma ca0b6ca1bc Explicitly states that the return value is seconds
The previous documentation hints that the return value if `other` `acts_like` time is seconds with the example, but it doesn't explicitly say "seconds" anywhere.  Just trying to make it more obvious that the value is seconds, and not something like milliseconds or nanoseconds, etc.
2022-05-24 12:35:36 -07:00
fatkodima 059d1d16ab Deprecate `:pool_size` and `:pool_timeout` options for configuring connection pooling in cache stores 2022-05-18 00:10:04 +03:00
Andrej Blagojević f48bf3975f Add initial value support to MemCacheStore #increment and #decrement 2022-05-17 18:32:52 +00:00
Joey Paris 98244c1d4b Squash commits 2022-05-15 11:45:22 +01:00
Alan Savage ad7b40c4f7 Fix MemoryStore#write(name, val, unless_exist: true) with expired entry 2022-05-11 11:54:03 -07:00
Matthew Draper a34fec7413 Bubble assertion failures back to the main thread
Without some help, failures in a forked process make for some noise in
the output, but won't fail the build.

Instead of trying to transfer the whole exception back, I've gone for a
simpler solution of just sending _something_ (the exception class name)
back so we'll fail; the full failure will be visible in the child
process's stderr output.
2022-05-11 15:56:27 +09:30
fatkodima ded8301375 Set ttl for redis and memcache cache stores when using `expires_at` 2022-05-10 14:37:11 +03:00
eileencodes 944bcb54f6
Fix tag helper regression
Vue.js, alpinejs, and potentially other JS libraries support tags
starting with `@` symbols. This was broken by the recent security release in
649516ce0f

I've only added `@` to the list even though there are potentially other
safe characters. We can add more if necessary (and if safe).

Fixes:
* #45014
* #44972
2022-05-05 10:42:41 -04:00
Jean Boussier c9a2bc284c Error reporting API: Add a source attribute
Ref: https://github.com/rails/rails/pull/43625#issuecomment-1109595539

Some users may not be interested by some internal errors.
By providing a `source` attribute we allow to easilly filter
these errors out.
2022-05-05 10:57:21 +02:00
Jean Boussier 1b884cfe8a
Merge pull request #44983 from shiro16/dalli-store-optimised-cache-read_multi
Fixed: MemCacheStore#read_multi_entries NoMethodError: undefined method `expired?` for nil:NilClass
2022-05-03 19:06:57 +02:00
Jean Boussier 70fc351619
Merge pull request #44980 from ghiculescu/isolation-level-config
Allow setting some Active Support settings via initializers
2022-05-03 09:53:52 +02:00
Chunwai Li de12c18a99 Emphasize cacheable objects in guide and API docs
Clarify to users what objects may be cached, and highlight the option used to cache default non-serializable data.

Purpose: Improving new-to-Rails users' experience, as this detail may not be obvious, costing them time and effort spent debugging.

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-05-02 15:15:59 -05:00
Alex Ghiculescu 2187bc78e1 Allow setting some active support settings via initializers 2022-05-01 09:02:21 +10:00
ext-shiro16 0beacc31b4 Fixed: NoMethodError: undefined method for nil:NilClass 2022-04-30 01:43:54 +09:00
ext-shiro16 070d049b36 add test case raw values from dalli store use read_multi_entries 2022-04-30 01:43:31 +09:00
Alvaro Martin Fraguas 649516ce0f
Fix and add protections for XSS in names.
Add the method ERB::Util.xml_name_escape to escape dangerous characters
in names of tags and names of attributes, following the specification of
XML.

Use that method in the tag helpers of ActionView::Helpers. Rename the option
:escape_attributes to :escape, to simplify by applying the option to the whole
tag.
2022-04-26 12:34:42 -07:00
Steven Harman 3b012a5254
Respect the formatter keyword arg on init
The stdlib Logger::new allows passing a :formatter keyword argument to
set the logger's formatter. ActiveSupport::Logger::new ignores this
argument by always setting the formatter to an instance of
SimpleFormatter. Instead, we should only set it when none is yet set.
2022-04-22 19:55:36 -04:00
Andrei Maxim dd851f3584
Access JDOM fields as constants in order to be compatibile with JRuby 9.3.x.x 2022-04-21 05:33:59 +03:00
Jonathan Hefner cdabe88d98
Merge pull request #44893 from ghousemohamed/add-docs-for-run-load-hooks
Add API docs for `run_load_hooks` [ci-skip]
2022-04-14 11:42:59 -05:00
Xavier Noria 2953ae5c8a Define config.enable_reloading to be !config.cache_classes
Every time I write `config.cache_classes` I have to pause for a moment to make
sure I get it right. It makes you think.

On the other hand, if you read `config.enable_reloading = true`, does the
application reload? You do not need to spend 1 cycle of brain CPU to nod.
2022-04-14 18:11:36 +02:00
Ghouse Mohamed 6a71188f9c Add API docs for run_load_hooks 2022-04-14 21:39:14 +05:30
Ryuta Kamizono 6bb0e0efb2
Merge pull request #44872 from entretechno/utc-12
Update ActiveSupport time zone tests for UTC-12 (International Date Line West)
2022-04-13 17:52:23 +09:00
Hartley McGuire afce06bdb2
fix warnings when eager loading on ruby 2.7
before:

```
ruby -w -Itest -Ilib -I../activesupport/lib -I../actionpack/lib
-I../actionview/lib -I../activemodel/lib
test/application/loading_test.rb

Run options: --seed 11862

............/home/hartley/dev/github.com/skipkayhil/rails/activesupport/lib/active_support/dependencies/autoload.rb:75:
warning: instance variable @_eagerloaded_constants not initialized
/home/hartley/dev/github.com/skipkayhil/rails/activesupport/lib/active_support/dependencies/autoload.rb:75:
warning: instance variable @_eagerloaded_constants not initialized
.../home/hartley/dev/github.com/skipkayhil/rails/activesupport/lib/active_support/dependencies/autoload.rb:75:
warning: instance variable @_eagerloaded_constants not initialized
/home/hartley/dev/github.com/skipkayhil/rails/activesupport/lib/active_support/dependencies/autoload.rb:75:
warning: instance variable @_eagerloaded_constants not initialized
/home/hartley/dev/github.com/skipkayhil/rails/activesupport/lib/active_support/dependencies/autoload.rb:75:
warning: instance variable @_eagerloaded_constants not initialized
...

Finished in 2.819071s, 6.3851 runs/s, 13.1249 assertions/s.
18 runs, 37 assertions, 0 failures, 0 errors, 0 skips
```

after:

```
ruby -w -Itest -Ilib -I../activesupport/lib -I../actionpack/lib
-I../actionview/lib -I../activemodel/lib
test/application/loading_test.rb

Run options: --seed 34841

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

Finished in 3.407082s, 5.2831 runs/s, 10.8597 assertions/s.
18 runs, 37 assertions, 0 failures, 0 errors, 0 skips
```
2022-04-12 23:51:34 -04:00
Jeremiah c75f94ab83 Update ActiveSupport time zone tests for UTC-12 (International Date Line West) 2022-04-11 09:35:41 -05:00
Gannon McGibbon 8d791726e1 Fix style in test/core_ext/enumerable_test.rb 2022-04-06 13:21:49 -04:00
Jean Boussier 94884da8f8 Handle renaming of `global_constant_state` in Ruby 3.2
Ref: https://github.com/ruby/ruby/pull/5766
2022-04-06 09:22:00 +02:00
Robin Dupret 4067f564a5 Fix next Rails version in intended removal
Following-up #44728
2022-04-03 14:35:21 +02:00
Pierre Jambet c1db4440e7
Improve default message for assert_changes
The default message would not tell you what the actual value is, just
what it expected it to have changed to or from.

It now tells you what the actual value is, similar to the output you'd
get from a matcher such as `assert_equal`
2022-03-31 15:58:38 -04:00
John Bampton 2d55c05c37 Fix case of `YAML` 2022-03-29 16:04:19 +10:00
John Bampton 3b7f55c179 Change `yaml` to `YAML` 2022-03-29 15:19:22 +10:00
Donatas Povilaitis 49fa92bb32 Fix `Range#overlaps?` for beginless ranges
- `#first` raises an error when called on a beginless range.
  Using `#begin` to get the first element instead.
- Adding additional equality condition to cover the case when both
  ranges are beginless
2022-03-23 22:40:24 +02:00
Ghouse Mohamed 70b8a76d98 Extends Ruby reserved keywords list in Module ext in Active Support 2022-03-23 22:14:16 +05:30
Hartley McGuire 458f4c48ec remove testing HWIA serialization for old psych
Psych 2.2.2 has been a default gem since Ruby 2.4.0, so testing against
< 2.0.9 is unnecessary
2022-03-22 23:31:45 -04:00
Andrew White 1943962a10
Deprecate preserving the pre-Ruby 2.4 behavior of `to_time`
With Ruby 2.4+ the default for +to_time+ changed from converting to the
local system time to preserving the offset of the receiver. At the time
Rails supported older versions of Ruby so a compatibility layer was
added to assist in the migration process. From Rails 5.0 new applications
have defaulted to the Ruby 2.4+ behavior and since Rails 7.0 now only
supports Ruby 2.7+ this compatibility layer can be safely removed.

To minimize any noise generated the deprecation warning only appears when
the setting is configured to `false` as that is the only scenario where
the removal of the compatibility layer has any effect.
2022-03-20 10:07:59 +00:00
Aaron Patterson 9ea0ee8135
Merge pull request #44724 from pixeltrix/allow-redis-url-configuration
Allow overriding of redis url when running tests
2022-03-19 14:53:24 -07:00
Andrew White 1c0c909bbb
Allow overriding of redis url when running tests
The tests for the redis cache store are hard-coded to use redis://localhost:6379/0
and redis://localhost:6379/1. This prevents them from running within a docker compose
environment where typically the url would be redis://redis:6379/0.
2022-03-19 10:31:27 +00:00
Kaíque Kandy Koga d78f266d19 Use duck_string instead of string 2022-03-18 20:28:33 -03:00
Aaron Patterson da22687eef
Merge pull request #44718 from ghousemohamed/extend-test-cases-for-object-in-activesupport
Add missing test cases for Object in activesupport
2022-03-18 16:14:06 -07:00
Ghouse Mohamed 5fa817241d Extends test cases for Object in activesupport 2022-03-18 15:34:04 +05:30
Rafael Mendonça França 50ba8d4e30
Merge pull request #44703 from ghousemohamed/test-should-test-for-multibyte-char
Fixes test cases for ActiveSupport multibyte chars
2022-03-16 17:15:35 -04:00
Rafael Mendonça França 5e770a3853
Merge pull request #44695 from Edouard-chin/ec-tagger-logger-broadcast
Fix TaggedLogging functionality when broadcasting to another logger:
2022-03-16 13:57:03 -04:00
Ghouse Mohamed ab99a4f37e multibyte_chars_test should test with ActiveSupport::Multibyte::Chars class as proxy 2022-03-16 19:46:52 +05:30
Rafael Mendonça França 5c1bd20f0d
Merge pull request #44693 from ghousemohamed/fix-docs-related-gem-versions
Fix `#version` method docs and some typos [ci-skip]
2022-03-15 16:28:07 -04:00
Ghouse Mohamed 6ee6cb554b Fix #version docs and some typos 2022-03-16 01:48:37 +05:30
Edouard CHIN 75aa3a07ec Fix TaggedLogging functionality when broadcasting:
- This PR fixes two issues with the Tagged Logging feature in
  conjunction with broadcasting logs.

  For the sake of clarity I'll define the "main logger" and
  the "broadcasted logger" in this snippet:

  ```ruby
    main_logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(io))
    broadcaster_logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(io))

    main_logger.extend(Activesupport::Logger.broadcast(broadcasted_logger))
  ```

  1) The first issue that this PR fixes, is that the tags on the "main logger"
     don't propagate to the "broadcasted logger" when you pass in a block.

     ```ruby
     main_logger.tagged("FOO") { |logger| logger.info("Hello") }

     # Outputs:
     # [Foo] Hello <- By the main logger
     # Hello       <- By the broadcasted logger
     ```

     A fix was made in 70af536b5d
     but that only works for the non block version

  2) It's quite common for the "broadcasted logger" to have a diffent
     log formatter that the "main logger". In example you'd want to
     output JSON logs in one and raw text in the other.

     That wasn't possible before. All loggers had to have the same
     instance of the formatter. The formatter was set on all loggers
     thanks to [this](3fc9d12875/activesupport/lib/active_support/logger.rb (L45-L48)) and it's [associated test](3fc9d12875/activesupport/test/broadcast_logger_test.rb (L58-L64))
     This requirement was needed to make the Tagged Logging feature
     work; the tags being set in a thread variable whose name
     uses the `object_id` 3fc9d12875/activesupport/lib/active_support/tagged_logging.rb (L59)
     (different formatter instance -> different object_id -> different variables)

     In this PR, I have removed the code that sets the same formatter
     instance on all logger. The "broadcaster logger" just need to
     have the `current_tags` point to the `current_tags` of the
     "main logger", I'm doing that by redefing the `current_tags`
     method each time the "main logger" uses a different formatter.

     The advantages by doing so is that custom made formatter
     can now call this `current_tags` method, which will return
     all the tags and process them the way they want.

     ```ruby
       class JSONLogFormatter
         def call(_, _, _, msg)
	   tags = current_tags # Can now retrieve the tags

	   { message: msg, tags: tags }.to_json
	 end
       end

       broadcasted_logger = Logger.new(io)
       broadcaster_logger.formatter = JSONLogFormatter.new
       main_logger = Logger.new(io)
       main_logger.extend(ActiveSupport::Logger.broadcast(broadcasted_logger))
     ```

     The behavior remains the same as before if a logger uses the
     Rails vanilla formatter or the Tagged Logging formatter.
2022-03-15 21:09:18 +01:00
Hartley McGuire 1faf619813 remove extra core_ext/object/blank requires
activerecord/lib/active_record/connection_adapters/postgresql/column.rb
- usage added in 64fd666
- unneeded because of active_support/rails: 8f58d6e

railties/lib/rails/rack/logger.rb
- usage added in c83d9a1
- usage removed in c131211

activesupport/lib/active_support/number_helper/number_converter.rb
- the NumberHelper was split into multiple classes in 2da9d67, however
  the require was left in NumberConverter even though
  NumberToPhoneConverter is the only class where it's used

activesupport/lib/active_support/duration/iso8601_serializer.rb
- usage added in 04c512d
- usage removed in 51e991f
2022-03-14 21:58:10 -04:00
Jonathan Hefner 5de5583f8b
Merge pull request #44678 from ghousemohamed/improvements-to-timezone-rdoc-activesupport
More rdoc improvements to activesupport [ci-skip]
2022-03-13 13:02:25 -05:00
Ghouse Mohamed 9d6cc4114b More rdoc improvements to activesupport 2022-03-13 23:22:48 +05:30
Ghouse Mohamed 475756db96 Fixed rdoc highlighting for ActiveSupport::KeyGenerator class 2022-03-13 22:02:49 +05:30
Kaíque Kandy Koga d89be419ba Add examples of default values using blocks for mattr_reader, mattr_writer and mattr_accessor 2022-03-09 18:58:08 -03:00
Ghouse Mohamed 42b2869d06 Removed unwanted requires of and fixed rubocop errors 2022-03-10 01:19:55 +05:30
Aaron Patterson 44e5a31d85
Merge pull request #44644 from tonobo/active_support_inheritable_options_add_dig
ActiveSupport::OrderedOptions handle custom #dig
2022-03-09 10:48:12 -08:00
Tim Foerster 5c15b586aa
ActiveSupport::OrderedOptions handle custom #dig
Common access via #[](arg) is being casted to symbol, same behavior should be provided on using #dig in order be consistent
2022-03-09 12:42:03 +01:00
Jean Boussier 6bbf8d647d Implement ErrorReporter#disable
Ref: https://github.com/rails/rails/pull/43625#discussion_r809532572

It can be used by error reporting service integration when they wish
to handle the error higher in the stack.

For instance Sidekiq has its own error handling interface with a
little bit of extra context information.
2022-03-07 16:10:27 +01:00
Jean Boussier e17fe9eb6e
Merge pull request #44459 from lewispb/default-error-reporting-handled-kwarg
Set a default value for ActiveSupport::ErrorReporter#report handled kwarg
2022-03-06 16:46:31 +01:00
Jean Boussier 25396b1c2a Avoid adding constants to Enumerable
Ref: https://github.com/aws/aws-sdk-ruby/pull/2670

Some gems like aws-sdk-core use `Object#extend(Enumerable)`.
It's not a very good pattern, but it's somehwat handled ok by Ruby.

However if Enumerable has constants, then any time the module is
extended, the global constant cache is flushed and this has a very
negative impact on performance for the virtual machine, and even
worse for JITs.
2022-03-04 13:33:17 +01:00
Jean Boussier 5772ecd7d5
Merge pull request #44593 from ghiculescu/patch-7
[docs] FileStore does not implement local cache
2022-03-02 10:29:32 +01:00
Jean Boussier db0c46461a
Merge pull request #44575 from Shopify/eager-auto-load
Modernize ActiveSupport::Autoload
2022-03-02 08:36:49 +01:00
Alex Ghiculescu dab0dd72da
[docs] FileStore does not implement local store
Oversight in https://github.com/rails/rails/pull/42626
2022-03-01 18:51:15 -07:00
Aaron Patterson ea9f0103fd
Revert "Revert "Merge pull request #42843 from buckley-w-david/message-verifier-default-serializer""
This reverts commit fd4e63cc28.
2022-03-01 15:14:43 -08:00
Aaron Patterson fd4e63cc28
Revert "Merge pull request #42843 from buckley-w-david/message-verifier-default-serializer"
This reverts commit a40d7815ac, reversing
changes made to ad2529be4b.
2022-03-01 13:58:40 -08:00
Saba Kiaei 5256c90327 Switch ActiveSupport::MessageVerifier's default serialization to JSON 2022-03-01 13:02:17 -05:00
Jean Boussier 9f7222b1ed Modernize ActiveSupport::Autoload
We no longer need to define instance variables to avoid uninitialized
instance variable warnings.

Also rather than to keep a hash of `constant -> path` forever, we
can simply keep a list of constants and call `const_get` for each of
them.

And finally we can clear the list we kept, as it's just wasted memory.
2022-03-01 09:06:04 +01:00
Jean Boussier f4d13563cd Don't setup i18n reloader if `config.cache_classes = true`
If Ruby code isn't reloaded I don't think i18n data should.

The reloader cause some small overhead in production.
2022-02-28 11:01:34 +01:00
Jonathan Hefner 497ab719d0
Merge pull request #44509 from jonathanhefner/apidocs-cross-link-docs
Cross-link API docs [ci-skip]
2022-02-23 12:08:41 -06:00
Matthew Draper e4140140af Warm-up to avoid autoloads interfering with class serial 2022-02-22 21:00:16 +10:30
Hartley McGuire 079a065257 remove unused requires in ActiveSupport::Cache
core_ext/array/wrap
- added in b1164adda1
- usage removed in fa986ae0ca

core_ext/numeric/time
- added in ee51b51b60, but usage was only
  in mem_cache_store so moved require there
2022-02-21 14:13:56 -05:00
Jonathan Hefner a199aaedb8 Cross-link API docs [ci-skip]
RDoc will automatically format and link API references as long as they
are not already marked up as inline code.

This commit removes markup from various API references so that those
references will link to the relevant API docs.
2022-02-21 11:45:25 -06:00
Jonathan Hefner 0c6ea785b6 Remove EventedFileUpdateChecker#updated? caveat [ci-skip]
Since #39718, `EventedFileUpdateChecker#updated?` no longer always
returns `true` after a fork.
2022-02-21 11:11:11 -06:00
Jonathan Hefner a801aa7cde Mark up inline code [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner e37adfed4e Add Oxford commas [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner 07bee949c4 Replace backticks with RDoc markup [ci-skip]
RDoc does not support backticks the way that Markdown does.  Instead,
inline code must be wrapped with `+` or `<tt>`.
2022-02-21 11:11:11 -06:00