Skip to content

Commit

Permalink
Properly set content type of uploaded file
Browse files Browse the repository at this point in the history
Uses MIME::Types library to guess the content type
  • Loading branch information
jnicklas committed Jan 7, 2010
1 parent fe6f5a1 commit 43f39b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Hoe.spec 'capybara' do

self.extra_deps = [
['nokogiri', '>= 1.3.3'],
['mime-types', '>= 1.16'],
['culerity', '>= 0.2.4'],
['selenium-webdriver', '>= 0.0.3'],
['rack', '>= 1.0.0'],
Expand Down
5 changes: 4 additions & 1 deletion lib/capybara/driver/rack_test_driver.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rack/test'
require 'mime/types'
require 'nokogiri'
require 'cgi'

Expand Down Expand Up @@ -86,7 +87,9 @@ def params(button)
node.xpath(".//input[@type='file']").map do |input|
unless input['value'].to_s.empty?
if multipart?
merge_param!(params, input['name'].to_s, Rack::Test::UploadedFile.new(input['value'].to_s))
content_type = MIME::Types.type_for(input['value'].to_s).first.to_s
file = Rack::Test::UploadedFile.new(input['value'].to_s, content_type)
merge_param!(params, input['name'].to_s, file)
else
merge_param!(params, input['name'].to_s, File.basename(input['value'].to_s))
end
Expand Down

0 comments on commit 43f39b9

Please sign in to comment.