Skip to content

Commit

Permalink
Allow symbols to be passed for extension aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
justincampbell committed Dec 17, 2011
1 parent 4f35d5a commit 4d5266e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/http/mime_type.rb
Expand Up @@ -103,7 +103,7 @@ def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], s
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)
Expand Down
11 changes: 11 additions & 0 deletions actionpack/test/dispatch/mime_type_test.rb
Expand Up @@ -95,6 +95,17 @@ class MimeTypeTest < ActiveSupport::TestCase
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 "type should be equal to symbol" do
assert_equal Mime::HTML, 'application/xhtml+xml'
assert_equal Mime::HTML, :html
Expand Down

0 comments on commit 4d5266e

Please sign in to comment.