Skip to content

Commit

Permalink
delegate_to_missing doesn't delegate private methods
Browse files Browse the repository at this point in the history
So we shouldn't claim they're there, even when asked explicitly.
  • Loading branch information
matthewd committed Apr 9, 2017
1 parent 8155577 commit 071882e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -267,7 +267,10 @@ def delegate_missing_to(target)

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)
Expand Down
10 changes: 10 additions & 0 deletions activesupport/test/core_ext/module_test.rb
Expand Up @@ -356,6 +356,16 @@ def test_delegate_to_missing_does_not_delegate_to_fake_methods
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
Expand Down

0 comments on commit 071882e

Please sign in to comment.