diff options
author | Matthew Draper <matthew@trebex.net> | 2017-04-09 20:07:12 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2017-04-09 20:07:12 +0930 |
commit | d928126725c5bc0019f0777e725e6c36f28dcb3e (patch) | |
tree | 13aa29336b5e872436494faa89550c613575eb97 /activesupport | |
parent | 071882e8ef6835cec7eb4e6ff965b99f4563b7aa (diff) | |
download | rails-d928126725c5bc0019f0777e725e6c36f28dcb3e.tar.gz rails-d928126725c5bc0019f0777e725e6c36f28dcb3e.tar.bz2 rails-d928126725c5bc0019f0777e725e6c36f28dcb3e.zip |
delegate_missing_to should fall back to super
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/delegation.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index ee2c3f54d1..85ab739095 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -270,7 +270,7 @@ class Module # It may look like an oversight, but we deliberately do not pass # +include_private+, because they do not get delegated. - #{target}.respond_to?(name) + #{target}.respond_to?(name) || super end def method_missing(method, *args, &block) diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 6d649f747c..085fd6592d 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -70,7 +70,23 @@ Product = Struct.new(:name) do end end +module ExtraMissing + def method_missing(sym, *args) + if sym == :extra_missing + 42 + else + super + end + end + + def respond_to_missing?(sym, priv = false) + sym == :extra_missing || super + end +end + DecoratedTester = Struct.new(:client) do + include ExtraMissing + delegate_missing_to :client end @@ -366,6 +382,12 @@ class ModuleTest < ActiveSupport::TestCase assert_not DecoratedTester.new(@david).respond_to?(:my_fake_method, true) end + def test_delegate_to_missing_respects_superclass_missing + assert_equal 42, DecoratedTester.new(@david).extra_missing + + assert_respond_to DecoratedTester.new(@david), :extra_missing + end + def test_delegate_with_case event = Event.new(Tester.new) assert_equal 1, event.foo |