From e8c710b11a02c6ab82b358fc671a14f378cb1974 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 23 May 2019 21:10:40 -0700 Subject: 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 in GitHub pull request 926. Minor changes to get it to apply, and to fix tests after applying by me. Fixes [Bug #11512] --- test/test_delegate.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'test/test_delegate.rb') 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 -- cgit v1.2.3