提交 c17724b1 编写于 作者: R Ryuta Kamizono

Fix `deprecate_methods` to not expand positional argument hash

上级 ec2e7d57
...@@ -58,29 +58,21 @@ def deprecate_methods(target_module, *method_names) ...@@ -58,29 +58,21 @@ def deprecate_methods(target_module, *method_names)
method_names.each do |method_name| method_names.each do |method_name|
if target_module.method_defined?(method_name) || target_module.private_method_defined?(method_name) if target_module.method_defined?(method_name) || target_module.private_method_defined?(method_name)
method = target_module.instance_method(method_name) method = target_module.instance_method(method_name)
if RUBY_VERSION < "2.7" target_module.module_eval do
target_module.redefine_method(method_name) do |*args, &block| redefine_method(method_name) do |*args, &block|
deprecator.deprecation_warning(method_name, options[method_name]) deprecator.deprecation_warning(method_name, options[method_name])
method.bind(self).call(*args, &block) method.bind(self).call(*args, &block)
end end
else ruby2_keywords(method_name) if respond_to?(:ruby2_keywords, true)
target_module.redefine_method(method_name) do |*args, **kwargs, &block|
deprecator.deprecation_warning(method_name, options[method_name])
method.bind(self).call(*args, **kwargs, &block)
end
end end
else else
mod ||= Module.new mod ||= Module.new
if RUBY_VERSION < "2.7" mod.module_eval do
mod.define_method(method_name) do |*args, &block| define_method(method_name) do |*args, &block|
deprecator.deprecation_warning(method_name, options[method_name]) deprecator.deprecation_warning(method_name, options[method_name])
super(*args, &block) super(*args, &block)
end end
else ruby2_keywords(method_name) if respond_to?(:ruby2_keywords, true)
mod.define_method(method_name) do |*args, **kwargs, &block|
deprecator.deprecation_warning(method_name, options[method_name])
super(*args, **kwargs, &block)
end
end end
end end
end end
......
...@@ -32,7 +32,7 @@ def f=(v); end ...@@ -32,7 +32,7 @@ def f=(v); end
deprecate :f= deprecate :f=
deprecate :g deprecate :g
def g; end def g(h) h end
module B module B
C = 1 C = 1
...@@ -85,7 +85,7 @@ def test_undeprecated ...@@ -85,7 +85,7 @@ def test_undeprecated
end end
end end
def test_deprecate_class_method def test_deprecate_method_on_class
assert_deprecated(/none is deprecated/) do assert_deprecated(/none is deprecated/) do
assert_equal 1, @dtc.none assert_equal 1, @dtc.none
end end
...@@ -99,6 +99,18 @@ def test_deprecate_class_method ...@@ -99,6 +99,18 @@ def test_deprecate_class_method
end end
end end
def test_deprecate_method_doesnt_expand_positional_argument_hash
hash = { k: 1 }
assert_deprecated(/one is deprecated/) do
assert_same hash, @dtc.one(hash)
end
assert_deprecated(/g is deprecated/) do
assert_same hash, @dtc.g(hash)
end
end
def test_deprecate_object def test_deprecate_object
deprecated_object = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, ":bomb:") deprecated_object = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, ":bomb:")
assert_deprecated(/:bomb:/) { deprecated_object.to_s } assert_deprecated(/:bomb:/) { deprecated_object.to_s }
...@@ -446,7 +458,7 @@ def test_custom_gem_name ...@@ -446,7 +458,7 @@ def test_custom_gem_name
end end
def test_deprecate_work_before_define_method def test_deprecate_work_before_define_method
assert_deprecated { @dtc.g } assert_deprecated(/g is deprecated/) { @dtc.g(1) }
end end
private private
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册