Permalink
Browse files

Implement Mime::Type#respond_to? (consistently with #method_missing)

  • Loading branch information...
1 parent 933ba0c commit 86cf3fb5faffa38a0337b4396926f53f8501e66f @dolzenko dolzenko committed Sep 25, 2011
Showing with 6 additions and 0 deletions.
  1. +4 −0 actionpack/lib/action_dispatch/http/mime_type.rb
  2. +2 −0 actionpack/test/dispatch/mime_type_test.rb
@@ -256,6 +256,10 @@ def html?
@@html_types.include?(to_sym) || @string =~ /html/
end
+ def respond_to?(method, include_private = false) #:nodoc:
+ super || method.to_s =~ /(\w+)\?$/
+ end
+
private
def method_missing(method, *args)
if method.to_s =~ /(\w+)\?$/
@@ -107,8 +107,10 @@ class MimeTypeTest < ActiveSupport::TestCase
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
+
types.each do |type|
mime = Mime.const_get(type.to_s.upcase)
+ assert mime.respond_to?("#{type}?"), "#{mime.inspect} does not respond to #{type}?"
assert mime.send("#{type}?"), "#{mime.inspect} is not #{type}?"
invalid_types = types - [type]
invalid_types.delete(:html) if Mime::Type.html_types.include?(type)

0 comments on commit 86cf3fb

Please sign in to comment.