diff options
Diffstat (limited to 'activesupport/test/array_inquirer_test.rb')
-rw-r--r-- | activesupport/test/array_inquirer_test.rb | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/activesupport/test/array_inquirer_test.rb b/activesupport/test/array_inquirer_test.rb index 263ab3802b..d5419b862d 100644 --- a/activesupport/test/array_inquirer_test.rb +++ b/activesupport/test/array_inquirer_test.rb @@ -1,9 +1,11 @@ -require 'abstract_unit' -require 'active_support/core_ext/array' +# frozen_string_literal: true + +require "abstract_unit" +require "active_support/core_ext/array" class ArrayInquirerTest < ActiveSupport::TestCase def setup - @array_inquirer = ActiveSupport::ArrayInquirer.new([:mobile, :tablet, 'api']) + @array_inquirer = ActiveSupport::ArrayInquirer.new([:mobile, :tablet, "api"]) end def test_individual @@ -19,7 +21,7 @@ class ArrayInquirerTest < ActiveSupport::TestCase end def test_any_string_symbol_mismatch - assert @array_inquirer.any?('mobile') + assert @array_inquirer.any?("mobile") assert @array_inquirer.any?(:api) end @@ -33,9 +35,29 @@ class ArrayInquirerTest < ActiveSupport::TestCase end def test_inquiry - result = [:mobile, :tablet, 'api'].inquiry + result = [:mobile, :tablet, "api"].inquiry assert_instance_of ActiveSupport::ArrayInquirer, result assert_equal @array_inquirer, result end + + def test_respond_to_fallback_to_array_respond_to + Array.class_eval do + def respond_to_missing?(name, include_private = false) + (name == :foo) || super + end + end + arr = ActiveSupport::ArrayInquirer.new([:x]) + + assert_respond_to arr, :can_you_hear_me? + assert_respond_to arr, :foo + assert_not_respond_to arr, :nope + ensure + Array.class_eval do + undef_method :respond_to_missing? + def respond_to_missing?(name, include_private = false) + super + end + end + end end |