diff options
author | yui-knk <spiketeika@gmail.com> | 2015-10-26 18:12:51 +0900 |
---|---|---|
committer | yui-knk <spiketeika@gmail.com> | 2015-10-26 19:40:46 +0900 |
commit | 7189e5554e44928698b01c59e833edfbebf0c6be (patch) | |
tree | 4ad237151b10a7efdeea8f7884c7940c306da5a8 /activesupport/test/core_ext | |
parent | 09463183867f702d6ec66fce964ecb9f7ae0d98a (diff) | |
download | rails-7189e5554e44928698b01c59e833edfbebf0c6be.tar.gz rails-7189e5554e44928698b01c59e833edfbebf0c6be.tar.bz2 rails-7189e5554e44928698b01c59e833edfbebf0c6be.zip |
Make `Module#redefine_method` to keep method visibility
Before this commit `Module#redefine_method` always changes
visibility of redefined method to `public`.
This commit changes behavior of Module#redefine_method` to
keep method visibility.
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/module/remove_method_test.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/activesupport/test/core_ext/module/remove_method_test.rb b/activesupport/test/core_ext/module/remove_method_test.rb index 77774afb0d..0d684dc70e 100644 --- a/activesupport/test/core_ext/module/remove_method_test.rb +++ b/activesupport/test/core_ext/module/remove_method_test.rb @@ -7,6 +7,16 @@ module RemoveMethodTests return 1 end + def do_something_protected + return 1 + end + protected :do_something_protected + + def do_something_private + return 1 + end + private :do_something_private + class << self def do_something_else return 2 @@ -34,8 +44,16 @@ class RemoveMethodTest < ActiveSupport::TestCase def test_redefine_method_in_an_object RemoveMethodTests::A.class_eval{ self.redefine_method(:do_something) { return 100 } + self.redefine_method(:do_something_protected) { return 100 } + self.redefine_method(:do_something_private) { return 100 } } assert_equal 100, RemoveMethodTests::A.new.do_something + assert_equal 100, RemoveMethodTests::A.new.send(:do_something_protected) + assert_equal 100, RemoveMethodTests::A.new.send(:do_something_private) + + assert RemoveMethodTests::A.public_method_defined? :do_something + assert RemoveMethodTests::A.protected_method_defined? :do_something_protected + assert RemoveMethodTests::A.private_method_defined? :do_something_private end -end
\ No newline at end of file +end |