diff options
author | José Valim <jose.valim@gmail.com> | 2011-09-25 05:26:18 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-09-25 05:26:18 -0700 |
commit | 61859298824cc688b56b93763cf70ae65efc9b64 (patch) | |
tree | f0a74a65b66358d89a0b236c6e8f30bf658b5ecf | |
parent | 933ba0cf6e20a5fac72ece21e5b51fbe485b3d90 (diff) | |
parent | 86cf3fb5faffa38a0337b4396926f53f8501e66f (diff) | |
download | rails-61859298824cc688b56b93763cf70ae65efc9b64.tar.gz rails-61859298824cc688b56b93763cf70ae65efc9b64.tar.bz2 rails-61859298824cc688b56b93763cf70ae65efc9b64.zip |
Merge pull request #3125 from dolzenko/master
Implement Mime::Type#respond_to? (consistently with #method_missing) Closes #3032
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_type.rb | 4 | ||||
-rw-r--r-- | actionpack/test/dispatch/mime_type_test.rb | 2 |
2 files changed, 6 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index fa2948c8db..8a9f9c4315 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -256,6 +256,10 @@ module Mime @@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+)\?$/ diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index 851fb59d51..08fe2127b9 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -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) |