Skip to content

Commit

Permalink
Implement Mime::Type#respond_to? (consistently with #method_missing)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolzenko committed Sep 25, 2011
1 parent 933ba0c commit 86cf3fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions actionpack/lib/action_dispatch/http/mime_type.rb
Expand Up @@ -256,6 +256,10 @@ def html?
@@html_types.include?(to_sym) || @string =~ /html/ @@html_types.include?(to_sym) || @string =~ /html/
end end


def respond_to?(method, include_private = false) #:nodoc:
super || method.to_s =~ /(\w+)\?$/
end

private private
def method_missing(method, *args) def method_missing(method, *args)
if method.to_s =~ /(\w+)\?$/ if method.to_s =~ /(\w+)\?$/
Expand Down
2 changes: 2 additions & 0 deletions actionpack/test/dispatch/mime_type_test.rb
Expand Up @@ -107,8 +107,10 @@ class MimeTypeTest < ActiveSupport::TestCase
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE # 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.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }



types.each do |type| types.each do |type|
mime = Mime.const_get(type.to_s.upcase) 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}?" assert mime.send("#{type}?"), "#{mime.inspect} is not #{type}?"
invalid_types = types - [type] invalid_types = types - [type]
invalid_types.delete(:html) if Mime::Type.html_types.include?(type) invalid_types.delete(:html) if Mime::Type.html_types.include?(type)
Expand Down

0 comments on commit 86cf3fb

Please sign in to comment.