delegate_to_missing doesn't delegate private methods

So we shouldn't claim they're there, even when asked explicitly.
This commit is contained in:
Matthew Draper 2017-04-09 19:53:31 +09:30
parent 81555776d4
commit 071882e8ef
2 changed files with 14 additions and 1 deletions

View File

@ -267,7 +267,10 @@ class Module
module_eval <<-RUBY, __FILE__, __LINE__ + 1
def respond_to_missing?(name, include_private = false)
#{target}.respond_to?(name, include_private)
# It may look like an oversight, but we deliberately do not pass
# +include_private+, because they do not get delegated.
#{target}.respond_to?(name)
end
def method_missing(method, *args, &block)

View File

@ -356,6 +356,16 @@ class ModuleTest < ActiveSupport::TestCase
assert_match(/undefined method `my_fake_method' for/, e.message)
end
def test_delegate_to_missing_affects_respond_to
assert DecoratedTester.new(@david).respond_to?(:name)
assert_not DecoratedTester.new(@david).respond_to?(:private_name)
assert_not DecoratedTester.new(@david).respond_to?(:my_fake_method)
assert DecoratedTester.new(@david).respond_to?(:name, true)
assert_not DecoratedTester.new(@david).respond_to?(:private_name, true)
assert_not DecoratedTester.new(@david).respond_to?(:my_fake_method, true)
end
def test_delegate_with_case
event = Event.new(Tester.new)
assert_equal 1, event.foo