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:
parent
c47686483e
commit
7b9cfde741
2 changed files with 14 additions and 2 deletions
|
@ -155,14 +155,15 @@ module ActiveSupport
|
||||||
@current_instances_key ||= name.to_sym
|
@current_instances_key ||= name.to_sym
|
||||||
end
|
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.
|
# Caches the method definition as a singleton method of the receiver.
|
||||||
#
|
#
|
||||||
# By letting #delegate handle it, we avoid an enclosure that'll capture args.
|
# By letting #delegate handle it, we avoid an enclosure that'll capture args.
|
||||||
singleton_class.delegate name, to: :instance
|
singleton_class.delegate name, to: :instance
|
||||||
|
|
||||||
send(name, *args, **kwargs, &block)
|
send(name, *args, &block)
|
||||||
end
|
end
|
||||||
|
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
||||||
|
|
||||||
def respond_to_missing?(name, _)
|
def respond_to_missing?(name, _)
|
||||||
super || instance.respond_to?(name)
|
super || instance.respond_to?(name)
|
||||||
|
|
|
@ -36,6 +36,12 @@ class CurrentAttributesTest < ActiveSupport::TestCase
|
||||||
self.account = account
|
self.account = account
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_world_and_account(hash)
|
||||||
|
hash[:world] = world
|
||||||
|
hash[:account] = account
|
||||||
|
hash
|
||||||
|
end
|
||||||
|
|
||||||
def respond_to_test; end
|
def respond_to_test; end
|
||||||
|
|
||||||
def request
|
def request
|
||||||
|
@ -138,6 +144,11 @@ class CurrentAttributesTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
assert_equal "world/1", Current.world
|
assert_equal "world/1", Current.world
|
||||||
assert_equal "account/1", Current.account
|
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
|
end
|
||||||
|
|
||||||
setup { @testing_teardown = false }
|
setup { @testing_teardown = false }
|
||||||
|
|
Loading…
Reference in a new issue