1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix method_missing delegation to not expand positional hash argument

Follow up to #41518, and similar to 3a85ced1a0.
This commit is contained in:
Ryuta Kamizono 2021-03-02 22:25:48 +09:00
parent c47686483e
commit 7b9cfde741
2 changed files with 14 additions and 2 deletions

View file

@ -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)

View file

@ -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 }