mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Fix uploading of file with no extension/MIME type using rack_test driver
This commit is contained in:
parent
2946385f84
commit
6cba19d647
3 changed files with 10 additions and 1 deletions
|
@ -42,7 +42,8 @@ class Capybara::RackTest::Form < Capybara::RackTest::Node
|
|||
if (value = field['value']).to_s.empty?
|
||||
NilUploadedFile.new
|
||||
else
|
||||
Rack::Test::UploadedFile.new(value, MiniMime.lookup_by_filename(value).content_type)
|
||||
mime_info = MiniMime.lookup_by_filename(value)
|
||||
Rack::Test::UploadedFile.new(value, (mime_info && mime_info.content_type).to_s)
|
||||
end
|
||||
merge_param!(params, field['name'].to_s, file)
|
||||
else
|
||||
|
|
1
lib/capybara/spec/fixtures/no_extension
vendored
Normal file
1
lib/capybara/spec/fixtures/no_extension
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
ThisFileHAsNoExtension
|
|
@ -4,6 +4,7 @@ Capybara::SpecHelper.spec "#attach_file" do
|
|||
@test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
|
||||
@another_test_file_path = File.expand_path('../fixtures/another_test_file.txt', File.dirname(__FILE__))
|
||||
@test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
|
||||
@no_extension_file_path = File.expand_path('../fixtures/no_extension', File.dirname(__FILE__))
|
||||
@session.visit('/form')
|
||||
end
|
||||
|
||||
|
@ -57,6 +58,12 @@ Capybara::SpecHelper.spec "#attach_file" do
|
|||
expect(@session).to have_content('image/jpeg')
|
||||
end
|
||||
|
||||
it "should not break when uploading a file without extension" do
|
||||
@session.attach_file "Single Document", @no_extension_file_path
|
||||
@session.click_button 'Upload Single'
|
||||
expect(@session).to have_content(File.read(@no_extension_file_path))
|
||||
end
|
||||
|
||||
it "should not break when using HTML5 multiple file input" do
|
||||
@session.attach_file "Multiple Documents", @test_file_path
|
||||
@session.click_button('Upload Multiple')
|
||||
|
|
Loading…
Reference in a new issue