From ec1b83d566c888d9d53d54b262def820f00834cb Mon Sep 17 00:00:00 2001 From: nashby Date: Fri, 17 Jun 2011 22:44:22 +0300 Subject: [PATCH] fix attachment extname --- lib/sinatra/base.rb | 1 + test/helpers_test.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 74442c45..be50c976 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -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 diff --git a/test/helpers_test.rb b/test/helpers_test.rb index 7a5198a9..548aa09d 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -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("") + 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 '', body + end + + end + describe 'send_file' do setup do @file = File.dirname(__FILE__) + '/file.txt'