aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-12-13 18:09:02 -0500
committerGitHub <noreply@github.com>2017-12-13 18:09:02 -0500
commitafdc6f29c1d014b21056822dc80a9f743f28b33a (patch)
tree2f3499978294f54c3c978910f2c4e16318630d47
parent6464683cee8c8752561020f69f6ea5722e98376f (diff)
parent9adaf605b4fb0075855c062c30fa4fdd96927b93 (diff)
downloadrails-afdc6f29c1d014b21056822dc80a9f743f28b33a.tar.gz
rails-afdc6f29c1d014b21056822dc80a9f743f28b33a.tar.bz2
rails-afdc6f29c1d014b21056822dc80a9f743f28b33a.zip
Merge pull request #31433 from jordan-brough/preserve-deprecated-method-visibility
Preserve original method visibility when deprecating a method
-rw-r--r--activesupport/lib/active_support/deprecation/method_wrappers.rb7
-rw-r--r--activesupport/test/deprecation/method_wrappers_test.rb22
2 files changed, 29 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/deprecation/method_wrappers.rb b/activesupport/lib/active_support/deprecation/method_wrappers.rb
index c4b78102eb..5be893d281 100644
--- a/activesupport/lib/active_support/deprecation/method_wrappers.rb
+++ b/activesupport/lib/active_support/deprecation/method_wrappers.rb
@@ -60,6 +60,13 @@ module ActiveSupport
deprecator.deprecation_warning(method_name, options[method_name])
super(*args, &block)
end
+
+ case
+ when target_module.protected_method_defined?(method_name)
+ protected method_name
+ when target_module.private_method_defined?(method_name)
+ private method_name
+ end
end
end
diff --git a/activesupport/test/deprecation/method_wrappers_test.rb b/activesupport/test/deprecation/method_wrappers_test.rb
index 04e2325754..439e117c1d 100644
--- a/activesupport/test/deprecation/method_wrappers_test.rb
+++ b/activesupport/test/deprecation/method_wrappers_test.rb
@@ -8,6 +8,16 @@ class MethodWrappersTest < ActiveSupport::TestCase
@klass = Class.new do
def new_method; "abc" end
alias_method :old_method, :new_method
+
+ protected
+
+ def new_protected_method; "abc" end
+ alias_method :old_protected_method, :new_protected_method
+
+ private
+
+ def new_private_method; "abc" end
+ alias_method :old_private_method, :new_private_method
end
end
@@ -33,4 +43,16 @@ class MethodWrappersTest < ActiveSupport::TestCase
assert_deprecated(warning, deprecator) { assert_equal "abc", @klass.new.old_method }
end
+
+ def test_deprecate_methods_protected_method
+ ActiveSupport::Deprecation.deprecate_methods(@klass, old_protected_method: :new_protected_method)
+
+ assert(@klass.protected_method_defined?(:old_protected_method))
+ end
+
+ def test_deprecate_methods_private_method
+ ActiveSupport::Deprecation.deprecate_methods(@klass, old_private_method: :new_private_method)
+
+ assert(@klass.private_method_defined?(:old_private_method))
+ end
end