Skip to content
This repository
Browse code

Allow symbols to be passed for extension aliases

  • Loading branch information...
commit 4d5266e2706195888c9f72fdc9ebde22f89a08df 1 parent 4f35d5a
Justin Campbell authored December 17, 2011
2  actionpack/lib/action_dispatch/http/mime_type.rb
@@ -103,7 +103,7 @@ def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], s
103 103
         SET << Mime.const_get(symbol.to_s.upcase)
104 104
 
105 105
         ([string] + mime_type_synonyms).each { |str| LOOKUP[str] = SET.last } unless skip_lookup
106  
-        ([symbol.to_s] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext] = SET.last }
  106
+        ([symbol] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext.to_s] = SET.last }
107 107
       end
108 108
 
109 109
       def parse(accept_header)
11  actionpack/test/dispatch/mime_type_test.rb
@@ -95,6 +95,17 @@ class MimeTypeTest < ActiveSupport::TestCase
95 95
     end
96 96
   end
97 97
 
  98
+  test "custom type with extension aliases" do
  99
+    begin
  100
+      Mime::Type.register "text/foobar", :foobar, [], [:foo, "bar"]
  101
+      %w[foobar foo bar].each do |extension|
  102
+        assert_equal Mime::FOOBAR, Mime::EXTENSION_LOOKUP[extension]
  103
+      end
  104
+    ensure
  105
+      Mime::Type.unregister(:FOOBAR)
  106
+    end
  107
+  end
  108
+
98 109
   test "type should be equal to symbol" do
99 110
     assert_equal Mime::HTML, 'application/xhtml+xml'
100 111
     assert_equal Mime::HTML, :html

0 notes on commit 4d5266e

Please sign in to comment.
Something went wrong with that request. Please try again.