From b99014bf44252e46e4e11e1df7cbded89e3e5465 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 15 Jan 2017 03:36:27 +0900 Subject: AS::StringInquirer#respond_to_missing? should fallback to super in case String or any other ancestor class' respond_to_missing? was defined. --- activesupport/CHANGELOG.md | 4 ++-- activesupport/lib/active_support/string_inquirer.rb | 2 +- activesupport/test/string_inquirer_test.rb | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index aefc94e0d9..0bb6b2466c 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,5 @@ -* Fixed a bug that `ArrayInquirer#respond_to_missing?` does not fallback to - `Array#respond_to_missing?`. +* Fixed bugs that `StringInquirer#respond_to_missing?` and + `ArrayInquirer#respond_to_missing?` do not fallback to `super`. *Akira Matsuda* diff --git a/activesupport/lib/active_support/string_inquirer.rb b/activesupport/lib/active_support/string_inquirer.rb index 09e1cbb28d..90eac89c9e 100644 --- a/activesupport/lib/active_support/string_inquirer.rb +++ b/activesupport/lib/active_support/string_inquirer.rb @@ -18,7 +18,7 @@ module ActiveSupport private def respond_to_missing?(method_name, include_private = false) - method_name[-1] == "?" + (method_name[-1] == "?") || super end def method_missing(method_name, *arguments) diff --git a/activesupport/test/string_inquirer_test.rb b/activesupport/test/string_inquirer_test.rb index d41e4d6800..2a5e7d02e4 100644 --- a/activesupport/test/string_inquirer_test.rb +++ b/activesupport/test/string_inquirer_test.rb @@ -20,4 +20,20 @@ class StringInquirerTest < ActiveSupport::TestCase def test_respond_to assert_respond_to @string_inquirer, :development? end + + def test_respond_to_fallback_to_string_respond_to + String.class_eval do + def respond_to_missing?(name, include_private = false) + (name == :bar) || super + end + end + str = ActiveSupport::StringInquirer.new("hello") + + assert_respond_to str, :are_you_ready? + assert_respond_to str, :bar + assert_not_respond_to str, :nope + + ensure + String.send :undef_method, :respond_to_missing? + end end -- cgit v1.2.3