diff options
author | Akira Matsuda <ronnie@dio.jp> | 2017-01-15 02:38:21 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2017-01-15 02:44:03 +0900 |
commit | d5fbb04fab6f598b2ad5a4763672504fa81466af (patch) | |
tree | 804cde73dfec98ebb5aa220966ddc531a0dc5ffd /activesupport | |
parent | c0c331bfc8ba66efa310c1c065e3b6349d97d9b2 (diff) | |
download | rails-d5fbb04fab6f598b2ad5a4763672504fa81466af.tar.gz rails-d5fbb04fab6f598b2ad5a4763672504fa81466af.tar.bz2 rails-d5fbb04fab6f598b2ad5a4763672504fa81466af.zip |
AS::ArrayInquirer#respond_to_missing? should fallback to super
in case Array or any other ancestor class' respond_to_missing? was defined.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/array_inquirer.rb | 2 | ||||
-rw-r--r-- | activesupport/test/array_inquirer_test.rb | 14 |
3 files changed, 20 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index fb9f5a447c..aefc94e0d9 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* Fixed a bug that `ArrayInquirer#respond_to_missing?` does not fallback to + `Array#respond_to_missing?`. + + *Akira Matsuda* + * Fix inconsistent results when parsing large durations and constructing durations from code ActiveSupport::Duration.parse('P3Y') == 3.years # It should be true diff --git a/activesupport/lib/active_support/array_inquirer.rb b/activesupport/lib/active_support/array_inquirer.rb index 85122e39b2..d364996e0b 100644 --- a/activesupport/lib/active_support/array_inquirer.rb +++ b/activesupport/lib/active_support/array_inquirer.rb @@ -32,7 +32,7 @@ module ActiveSupport private def respond_to_missing?(name, include_private = false) - name[-1] == "?" + (name[-1] == "?") || super end def method_missing(name, *args) diff --git a/activesupport/test/array_inquirer_test.rb b/activesupport/test/array_inquirer_test.rb index 4d3f5b001c..3ed48dd49d 100644 --- a/activesupport/test/array_inquirer_test.rb +++ b/activesupport/test/array_inquirer_test.rb @@ -38,4 +38,18 @@ class ArrayInquirerTest < ActiveSupport::TestCase assert_instance_of ActiveSupport::ArrayInquirer, result assert_equal @array_inquirer, result end + + def test_respond_to_fallback_to_array_respond_to + arr = ActiveSupport::ArrayInquirer.new([:x]) + # This kind of emulates a situation that Array#respond_to_missing? is defined + arr.singleton_class.class_eval do + def respond_to_missing?(name, _include_private = false) + (name == :foo) || super + end + end + + assert_respond_to arr, :can_you_hear_me? + assert_respond_to arr, :foo + assert_not_respond_to arr, :nope + end end |