Skip to content

Commit

Permalink
add Mime.fetch so we can have default mime types
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jul 4, 2012
1 parent 142d50e commit 7ef6a27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions actionpack/lib/action_controller/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,7 @@ def build_request_uri(action, parameters)

def html_format?(parameters)
return true unless parameters.is_a?(Hash)
format = Mime[parameters[:format]]
format.nil? || format.html?
Mime.fetch(parameters[:format]) { Mime['html'] }.html?
end
end

Expand Down
5 changes: 5 additions & 0 deletions actionpack/lib/action_dispatch/http/mime_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def self.[](type)
Type.lookup_by_extension(type.to_s)
end

def self.fetch(type)
return type if type.is_a?(Type)
EXTENSION_LOOKUP.fetch(type.to_s) { |k| yield k }
end

# Encapsulates the notion of a mime type. Can be used at render time, for example, with:
#
# class PostsController < ActionController::Base
Expand Down

0 comments on commit 7ef6a27

Please sign in to comment.