diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-21 14:10:17 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-21 14:10:17 -0700 |
commit | f8ba48c150fb70ed0bcb8ff74cf2aabc81173082 (patch) | |
tree | ada3ef19522f883e7de3a8a094456fb2c2feb134 /actionpack | |
parent | 7cdb2ec9636288dce25836c3ec0f261537a6425f (diff) | |
download | rails-f8ba48c150fb70ed0bcb8ff74cf2aabc81173082.tar.gz rails-f8ba48c150fb70ed0bcb8ff74cf2aabc81173082.tar.bz2 rails-f8ba48c150fb70ed0bcb8ff74cf2aabc81173082.zip |
introduce an `All` mime type
This class gives us the `all?` predicate method that returns true
without hitting method missing
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_type.rb | 6 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_types.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/mime_type_test.rb | 6 |
3 files changed, 11 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index 2d49ad661c..553f19b5bc 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -331,6 +331,7 @@ to: @@html_types.include?(to_sym) || @string =~ /html/ end + def all?; false; end private @@ -348,6 +349,11 @@ to: def respond_to_missing?(method, include_private = false) #:nodoc: method.to_s.ends_with? '?' end + + class All < Type + def all?; true; end + def html?; true; end + end end class NullType diff --git a/actionpack/lib/action_dispatch/http/mime_types.rb b/actionpack/lib/action_dispatch/http/mime_types.rb index d349cf2807..0af3e5c0df 100644 --- a/actionpack/lib/action_dispatch/http/mime_types.rb +++ b/actionpack/lib/action_dispatch/http/mime_types.rb @@ -33,4 +33,4 @@ Mime::Type.register "application/pdf", :pdf, [], %w(pdf) Mime::Type.register "application/zip", :zip, [], %w(zip) # Create Mime::ALL but do not add it to the SET. -Mime::Type.add_type :ALL, Mime::Type.new("*/*", :all, []) +Mime::Type.add_type :ALL, Mime::Type::All.new("*/*", :all, []) diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index 520864b7d9..791c6ff625 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -163,10 +163,12 @@ class MimeTypeTest < ActiveSupport::TestCase types.each do |type| mime = Mime::Type[type.upcase] assert mime.respond_to?("#{type}?"), "#{mime.inspect} does not respond to #{type}?" - assert mime.send("#{type}?"), "#{mime.inspect} is not #{type}?" + assert_equal type, mime.symbol, "#{mime.inspect} is not #{type}?" invalid_types = types - [type] invalid_types.delete(:html) if Mime::Type.html_types.include?(type) - invalid_types.each { |other_type| assert !mime.send("#{other_type}?"), "#{mime.inspect} is #{other_type}?" } + invalid_types.each { |other_type| + assert_not_equal mime.symbol, other_type, "#{mime.inspect} is #{other_type}?" + } end end |