Skip to content

Commit

Permalink
Fix uploading of file with no extension/MIME type using rack_test driver
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Aug 4, 2017
1 parent 2946385 commit 6cba19d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/capybara/rack_test/form.rb
Expand Up @@ -42,7 +42,8 @@ def params(button)
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
Expand Down
1 change: 1 addition & 0 deletions lib/capybara/spec/fixtures/no_extension
@@ -0,0 +1 @@
ThisFileHAsNoExtension
7 changes: 7 additions & 0 deletions lib/capybara/spec/session/attach_file_spec.rb
Expand Up @@ -4,6 +4,7 @@
@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

Expand Down Expand Up @@ -57,6 +58,12 @@
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')
Expand Down

0 comments on commit 6cba19d

Please sign in to comment.