fix attachment extname

This commit is contained in:
nashby 2011-06-17 22:44:22 +03:00
parent 21bc6271d5
commit ec1b83d566
2 changed files with 20 additions and 0 deletions

View File

@ -189,6 +189,7 @@ module Sinatra
if filename
params = '; filename="%s"' % File.basename(filename)
response['Content-Disposition'] << params
content_type(File.extname(filename))
end
end

View File

@ -576,6 +576,25 @@ class HelpersTest < Test::Unit::TestCase
end
end
describe 'attachment' do
def attachment_app(filename=nil)
mock_app {
get '/attachment' do
attachment filename
response.write("<sinatra></sinatra>")
end
}
end
it 'sets the Content-Type response header' do
attachment_app('test.xml')
get '/attachment'
assert_equal 'application/xml;charset=utf-8', response['Content-Type']
assert_equal '<sinatra></sinatra>', body
end
end
describe 'send_file' do
setup do
@file = File.dirname(__FILE__) + '/file.txt'