1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Properly set content type of uploaded file

Uses MIME::Types library to guess the content type
This commit is contained in:
Jonas Nicklas 2010-01-07 23:49:09 +01:00
parent fe6f5a1bde
commit 43f39b9979
2 changed files with 5 additions and 1 deletions

View file

@ -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'],

View file

@ -1,4 +1,5 @@
require 'rack/test'
require 'mime/types'
require 'nokogiri'
require 'cgi'
@ -86,7 +87,9 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
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