make use mime_type returns a string or nil

This commit is contained in:
Konstantin Haase 2013-03-10 17:01:06 +01:00
parent 8fa3c5cc0f
commit f1538bf6df
2 changed files with 8 additions and 1 deletions

View File

@ -1255,7 +1255,8 @@ module Sinatra
# Lookup or register a mime type in Rack's mime registry.
def mime_type(type, value = nil)
return type if type.nil? || type.to_s.include?('/')
return type if type.nil?
return type.to_s if type.to_s.include?('/')
type = ".#{type}" unless type.to_s[0] == ?.
return Rack::Mime.mime_type(type, nil) unless value
Rack::Mime::MIME_TYPES[type] = value

View File

@ -574,6 +574,12 @@ class HelpersTest < Test::Unit::TestCase
it 'returns the argument when given a media type string' do
assert_equal 'text/plain', mime_type('text/plain')
end
it 'turns AcceptEntry into String' do
type = mime_type(Sinatra::Request::AcceptEntry.new('text/plain'))
assert_equal String, type.class
assert_equal 'text/plain', type
end
end
test 'Base.mime_type registers mime type' do