Avoid adding new method to `ActiveSupport`.

We don't need this delegation and can be setting directly to the right
object.

Also document the new configuration.
This commit is contained in:
Rafael Mendonça França 2021-11-02 01:12:32 +00:00 committed by GitHub
parent fbd11abe46
commit 33ca392317
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 19 deletions

View File

@ -1,9 +1,3 @@
# frozen_string_literal: true
require "active_support/core_ext/digest/uuid"
module ActiveSupport
class << self
delegate :use_rfc4122_namespaced_uuids, :use_rfc4122_namespaced_uuids=, to: :'Digest::UUID'
end
end

View File

@ -133,7 +133,7 @@ module ActiveSupport
config.after_initialize do
if app.config.active_support.use_rfc4122_namespaced_uuids
require "active_support/core_ext/digest"
ActiveSupport.use_rfc4122_namespaced_uuids = app.config.active_support.use_rfc4122_namespaced_uuids
::Digest::UUID.use_rfc4122_namespaced_uuids = app.config.active_support.use_rfc4122_namespaced_uuids
end
end
end

View File

@ -4,14 +4,6 @@ require_relative "../../abstract_unit"
require "active_support/core_ext/digest"
class DigestUUIDExt < ActiveSupport::TestCase
def with_use_rfc4122_namespaced_uuids_set
old_value = ActiveSupport.use_rfc4122_namespaced_uuids
ActiveSupport.use_rfc4122_namespaced_uuids = true
yield
ensure
ActiveSupport.use_rfc4122_namespaced_uuids = old_value
end
def test_constants
assert_equal "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "%08x-%04x-%04x-%04x-%04x%08x" % Digest::UUID::DNS_NAMESPACE.unpack("NnnnnN")
assert_equal "6ba7b811-9dad-11d1-80b4-00c04fd430c8", "%08x-%04x-%04x-%04x-%04x%08x" % Digest::UUID::URL_NAMESPACE.unpack("NnnnnN")
@ -184,4 +176,13 @@ class DigestUUIDExt < ActiveSupport::TestCase
Digest::UUID.uuid_from_hash(OpenSSL::Digest::SHA256, Digest::UUID::OID_NAMESPACE, "1.2.3")
end
end
private
def with_use_rfc4122_namespaced_uuids_set
old_value = Digest::UUID.use_rfc4122_namespaced_uuids
Digest::UUID.use_rfc4122_namespaced_uuids = true
yield
ensure
Digest::UUID.use_rfc4122_namespaced_uuids = old_value
end
end

View File

@ -1729,6 +1729,7 @@ Accepts a string for the HTML tag used to wrap attachments. Defaults to `"action
- `config.active_support.cache_format_version`: `7.0`
- `config.active_support.remove_deprecated_time_with_zone_name`: `true`
- `config.active_support.executor_around_test_case`: `true`
- `config.active_support.use_rfc4122_namespaced_uuids`: `true`
- `config.action_dispatch.return_only_request_media_type_on_content_type`: `false`
- `config.action_controller.silence_disabled_session_errors`: `false`
- `config.action_mailer.smtp_timeout`: `5`
@ -1816,6 +1817,7 @@ Accepts a string for the HTML tag used to wrap attachments. Defaults to `"action
- `config.active_support.key_generator_hash_digest_class`: `OpenSSL::Digest::SHA1`
- `config.active_support.cache_format_version`: `6.1`
- `config.active_support.executor_around_test_case`: `false`
- ``config.active_support.use_rfc4122_namespaced_uuids``: `false`
- `config.action_dispatch.return_only_request_media_type_on_content_type`: `true`
- `ActiveSupport.utc_to_local_returns_utc_offset_times`: `false`
- `config.action_mailer.smtp_timeout`: `nil`

View File

@ -97,3 +97,10 @@
# Previously this was set in an initializer. It's fine to keep using that initializer if you've customized it.
# To disable parameter wrapping entirely, set this config to `false`.
# Rails.application.config.action_controller.wrap_parameters_by_default = true
# Specifies whether generated namespaced UUIDs follow the RFC 4122 standard for namespace IDs provided as a
# `String` to `Digest::UUID.uuid_v3` or `Digest::UUID.uuid_v5` method calls.
#
# See https://guides.rubyonrails.org/configuring.html#config-active-support-use-rfc4122-namespaced-uuids for
# more information
# Rails.application.config.active_support.use_rfc4122_namespaced_uuids = true

View File

@ -2422,18 +2422,18 @@ module ApplicationTests
assert_equal 1234, ActiveSupport.test_parallelization_threshold
end
test "ActiveSupport.use_rfc4122_namespaced_uuids is enabled by default for new apps" do
test "Digest::UUID.use_rfc4122_namespaced_uuids is enabled by default for new apps" do
app "development"
assert_equal true, ActiveSupport.use_rfc4122_namespaced_uuids
assert_equal true, Digest::UUID.use_rfc4122_namespaced_uuids
end
test "ActiveSupport.use_rfc4122_namespaced_uuids is disabled by default for upgraded apps" do
test "Digest::UUID.use_rfc4122_namespaced_uuids is disabled by default for upgraded apps" do
remove_from_config '.*config\.load_defaults.*\n'
app "development"
assert_equal false, ActiveSupport.use_rfc4122_namespaced_uuids
assert_equal false, Digest::UUID.use_rfc4122_namespaced_uuids
end
test "custom serializers should be able to set via config.active_job.custom_serializers in an initializer" do