diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-17 05:58:18 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-17 05:58:18 -0800 |
commit | 941213040bc2dc09f2654c0235f2c681c6d1c097 (patch) | |
tree | cf497628691f757032b5f99ba0b9fdbd80e320ac | |
parent | 8de96949e9d3d8f0902486df343ad88401c028fd (diff) | |
parent | 27f3619cd5d3700b2ff16f7c153c3549316b9410 (diff) | |
download | rails-941213040bc2dc09f2654c0235f2c681c6d1c097.tar.gz rails-941213040bc2dc09f2654c0235f2c681c6d1c097.tar.bz2 rails-941213040bc2dc09f2654c0235f2c681c6d1c097.zip |
Merge pull request #4012 from JustinCampbell/master
Allow symbols to be passed as extension aliases in Mime::Type.register
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_type.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/mime_type_test.rb | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index 8a9f9c4315..25affb9f50 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -103,7 +103,7 @@ module Mime SET << Mime.const_get(symbol.to_s.upcase) ([string] + mime_type_synonyms).each { |str| LOOKUP[str] = SET.last } unless skip_lookup - ([symbol.to_s] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext] = SET.last } + ([symbol] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext.to_s] = SET.last } end def parse(accept_header) diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index 08fe2127b9..db21080c42 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -95,6 +95,37 @@ class MimeTypeTest < ActiveSupport::TestCase end end + test "custom type with type aliases" do + begin + Mime::Type.register "text/foobar", :foobar, ["text/foo", "text/bar"] + %w[text/foobar text/foo text/bar].each do |type| + assert_equal Mime::FOOBAR, type + end + ensure + Mime::Type.unregister(:FOOBAR) + end + end + + test "custom type with extension aliases" do + begin + Mime::Type.register "text/foobar", :foobar, [], [:foo, "bar"] + %w[foobar foo bar].each do |extension| + assert_equal Mime::FOOBAR, Mime::EXTENSION_LOOKUP[extension] + end + ensure + Mime::Type.unregister(:FOOBAR) + end + end + + test "register alias" do + begin + Mime::Type.register_alias "application/xhtml+xml", :foobar + assert_equal Mime::HTML, Mime::EXTENSION_LOOKUP['foobar'] + ensure + Mime::Type.unregister(:FOOBAR) + end + end + test "type should be equal to symbol" do assert_equal Mime::HTML, 'application/xhtml+xml' assert_equal Mime::HTML, :html |