1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activesupport/test/deprecation
Jordan Brough 9adaf605b4 Preserve original method visibility when deprecating a method
This commit fixes `deprecate` so that it preserves method visibility (like it
did previously when it was utilizing `alias_method_chain`).

When Module#prepend replaced alias_method_chain in a982a42 it caused deprecated
methods to always become public.

`alias_method_chain` had this bit of code:
https://github.com/rails/rails/blob/v5.0.6/activesupport/lib/active_support/core_ext/module/aliasing.rb#L40-L47
which preserved method visibility.

Without this fix, a workaround would be:

```ruby
class C8
  private

  def new_method
  end

  def old_method
  end
  deprecate :old_method, :new_method
  # workaround:
  instance_method(:old_method).owner.send(:private, :old_method)
end
```

Because the visibility needs to be fixed on the Module prepended by
MethodWrapper.
2017-12-13 13:18:03 -07:00
..
method_wrappers_test.rb Preserve original method visibility when deprecating a method 2017-12-13 13:18:03 -07:00
proxy_wrappers_test.rb [Active Support] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00