From a1beec1de001f822ee62e4b2d6450bcc2aafb56b Mon Sep 17 00:00:00 2001 From: Aleksey Magusev Date: Sun, 5 Aug 2012 23:30:01 +0400 Subject: Add AS::StringInquirer#respond_to? method Consistently with #method_missing --- activesupport/lib/active_support/string_inquirer.rb | 18 ++++++++++++------ activesupport/test/string_inquirer_test.rb | 14 +++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/activesupport/lib/active_support/string_inquirer.rb b/activesupport/lib/active_support/string_inquirer.rb index f3f3909a90..5f20bfa7bc 100644 --- a/activesupport/lib/active_support/string_inquirer.rb +++ b/activesupport/lib/active_support/string_inquirer.rb @@ -10,12 +10,18 @@ module ActiveSupport # Rails.env.production? # class StringInquirer < String - def method_missing(method_name, *arguments) - if method_name[-1, 1] == "?" - self == method_name[0..-2] - else - super + private + + def respond_to_missing?(method_name, include_private = false) + method_name[-1] == '?' + end + + def method_missing(method_name, *arguments) + if method_name[-1] == '?' + self == method_name[0..-2] + else + super + end end - end end end diff --git a/activesupport/test/string_inquirer_test.rb b/activesupport/test/string_inquirer_test.rb index bb15916e9e..94d5fe197d 100644 --- a/activesupport/test/string_inquirer_test.rb +++ b/activesupport/test/string_inquirer_test.rb @@ -1,15 +1,23 @@ require 'abstract_unit' class StringInquirerTest < ActiveSupport::TestCase + def setup + @string_inquirer = ActiveSupport::StringInquirer.new('production') + end + def test_match - assert ActiveSupport::StringInquirer.new("production").production? + assert @string_inquirer.production? end def test_miss - assert !ActiveSupport::StringInquirer.new("production").development? + refute @string_inquirer.development? end def test_missing_question_mark - assert_raise(NoMethodError) { ActiveSupport::StringInquirer.new("production").production } + assert_raise(NoMethodError) { @string_inquirer.production } + end + + def test_respond_to + assert_respond_to @string_inquirer, :development? end end -- cgit v1.2.3