summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-05-23 21:10:40 -0700
committerJeremy Evans <code@jeremyevans.net>2019-05-30 18:34:45 -0700
commite8c710b11a02c6ab82b358fc671a14f378cb1974 (patch)
tree591a8d416acc81ec2306064fdebbd001b45806ed /test
parent1cd93f1cdfbe6f7e71b05b3f8e707f21d70e94ba (diff)
Fix visibility of some methods when using DelegateClass
Public instance methods added to a delegated class after the creation of the delegate class were not returned by the public_instance_methods class method of the delegate class. Protected instance methods in the delegated class when the delegate class is created were returned by the public_methods instance method of the delegate class. Patch mostly from Kenichi Kamiya <kachick1@gmail.com> in GitHub pull request 926. Minor changes to get it to apply, and to fix tests after applying by me. Fixes [Bug #11512]
Diffstat (limited to 'test')
-rw-r--r--test/test_delegate.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test_delegate.rb b/test/test_delegate.rb
index 8ed3342afa..38e38ad781 100644
--- a/test/test_delegate.rb
+++ b/test/test_delegate.rb
@@ -85,6 +85,37 @@ class TestDelegateClass < Test::Unit::TestCase
assert_equal(:m, bar.send(:delegate_test_m), bug)
end
+ class Parent
+ def parent_public; end
+
+ protected
+
+ def parent_protected; end
+ end
+
+ class Child < DelegateClass(Parent)
+ end
+
+ class Parent
+ def parent_public_added; end
+
+ protected
+
+ def parent_protected_added; end
+ end
+
+ def test_public_instance_methods
+ ignores = Object.public_instance_methods | Delegator.public_instance_methods
+ assert_equal([:parent_public, :parent_public_added], (Child.public_instance_methods - ignores).sort)
+ assert_equal([:parent_public, :parent_public_added], (Child.new(Parent.new).public_methods - ignores).sort)
+ end
+
+ def test_protected_instance_methods
+ ignores = Object.protected_instance_methods | Delegator.protected_instance_methods
+ assert_equal([:parent_protected, :parent_protected_added], (Child.protected_instance_methods - ignores).sort)
+ assert_equal([:parent_protected, :parent_protected_added], (Child.new(Parent.new).protected_methods - ignores).sort)
+ end
+
class IV < DelegateClass(Integer)
attr_accessor :var