mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
make use mime_type returns a string or nil
This commit is contained in:
parent
8fa3c5cc0f
commit
f1538bf6df
2 changed files with 8 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue