Add AS::StringInquirer#respond_to? method
Consistently with #method_missing
This commit is contained in:
parent
daf9f9ffa6
commit
a1beec1de0
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue