mirror of https://github.com/rails/rails
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:
parent
81555776d4
commit
071882e8ef
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue