From 7b9cfde741662603f7fdd78698190b2fdefead17 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 2 Mar 2021 22:25:48 +0900 Subject: [PATCH] Fix `method_missing` delegation to not expand positional hash argument Follow up to #41518, and similar to 3a85ced1a03c3e4fa81e316d06a65a75c760cf8c. --- .../lib/active_support/current_attributes.rb | 5 +++-- activesupport/test/current_attributes_test.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/current_attributes.rb b/activesupport/lib/active_support/current_attributes.rb index 3d3031ad94..00dcfe99c4 100644 --- a/activesupport/lib/active_support/current_attributes.rb +++ b/activesupport/lib/active_support/current_attributes.rb @@ -155,14 +155,15 @@ module ActiveSupport @current_instances_key ||= name.to_sym end - def method_missing(name, *args, **kwargs, &block) + def method_missing(name, *args, &block) # Caches the method definition as a singleton method of the receiver. # # By letting #delegate handle it, we avoid an enclosure that'll capture args. singleton_class.delegate name, to: :instance - send(name, *args, **kwargs, &block) + send(name, *args, &block) end + ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true) def respond_to_missing?(name, _) super || instance.respond_to?(name) diff --git a/activesupport/test/current_attributes_test.rb b/activesupport/test/current_attributes_test.rb index 024ccec499..802fbedba9 100644 --- a/activesupport/test/current_attributes_test.rb +++ b/activesupport/test/current_attributes_test.rb @@ -36,6 +36,12 @@ class CurrentAttributesTest < ActiveSupport::TestCase self.account = account end + def get_world_and_account(hash) + hash[:world] = world + hash[:account] = account + hash + end + def respond_to_test; end def request @@ -138,6 +144,11 @@ class CurrentAttributesTest < ActiveSupport::TestCase assert_equal "world/1", Current.world assert_equal "account/1", Current.account + + hash = {} + assert_same hash, Current.get_world_and_account(hash) + assert_equal "world/1", hash[:world] + assert_equal "account/1", hash[:account] end setup { @testing_teardown = false }