Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve original method visibility when deprecating a method #31433

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ def deprecate_methods(target_module, *method_names)
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

Expand Down
22 changes: 22 additions & 0 deletions activesupport/test/deprecation/method_wrappers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ def setup
@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

Expand All @@ -33,4 +43,16 @@ def test_deprecate_methods_warning_when_deprecated_with_custom_deprecator

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