Fix support for a file input which is not filled in.
This commit is contained in:
parent
e71d66b791
commit
70fe114518
|
@ -83,10 +83,12 @@ class Capybara::Driver::RackTest
|
|||
agg
|
||||
end
|
||||
params += node.xpath(".//input[@type='file']").inject([]) do |agg, input|
|
||||
if multipart?
|
||||
agg << [input['name'].to_s, Rack::Test::UploadedFile.new(input['value'].to_s)]
|
||||
else
|
||||
agg << [input['name'].to_s, File.basename(input['value'].to_s)]
|
||||
if input['value'].to_s.any?
|
||||
if multipart?
|
||||
agg << [input['name'].to_s, Rack::Test::UploadedFile.new(input['value'].to_s)]
|
||||
else
|
||||
agg << [input['name'].to_s, File.basename(input['value'].to_s)]
|
||||
end
|
||||
end
|
||||
agg
|
||||
end
|
||||
|
|
|
@ -486,6 +486,10 @@ shared_examples_for "session" do
|
|||
@session.click_button('Upload')
|
||||
@session.body.should include(File.read(@test_file_path))
|
||||
end
|
||||
|
||||
it "should not break if no file is submitted" do
|
||||
@session.click_button('Upload')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -50,7 +50,7 @@ class TestApp < Sinatra::Base
|
|||
end
|
||||
|
||||
post '/upload' do
|
||||
params[:form][:document][:tempfile].read
|
||||
params[:form][:document][:tempfile].read rescue ''
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -101,6 +101,11 @@
|
|||
</form>
|
||||
|
||||
<form action="/upload" method="post" enctype="multipart/form-data">
|
||||
<p>
|
||||
<label for="form_name">Name</label>
|
||||
<input type="file" name="form[name]" id="form_name"/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="form_document">Document</label>
|
||||
<input type="file" name="form[document]" id="form_document"/>
|
||||
|
|
Loading…
Reference in New Issue