Work around mime-types broken sorting on MIME::Types.type_for('xxx.csv')

This commit is contained in:
Thomas Walpole 2016-09-12 18:55:17 -07:00
parent 2c910e7f9a
commit e0e187cbea
3 changed files with 11 additions and 1 deletions

View File

@ -42,7 +42,8 @@ class Capybara::RackTest::Form < Capybara::RackTest::Node
if (value = field['value']).to_s.empty?
NilUploadedFile.new
else
content_type = MIME::Types.type_for(value).first.to_s
types = MIME::Types.type_for(value)
content_type = types.sort_by.with_index { |type, idx| [type.obsolete? ? 1 : 0, idx] }.first.to_s
Rack::Test::UploadedFile.new(value, content_type)
end
merge_param!(params, field['name'].to_s, file)

1
spec/fixtures/capybara.csv vendored Normal file
View File

@ -0,0 +1 @@
test, mime-type, file
1 test mime-type file

View File

@ -79,6 +79,14 @@ RSpec.describe Capybara::Session do
expect(@session.html).to include('Successfully ignored empty file field.')
end
end
it "should not submit an obsolete mime type" do
@test_jpg_file_path = File.expand_path('fixtures/capybara.csv', File.dirname(__FILE__))
@session.visit("/form")
@session.attach_file "form_document", @test_jpg_file_path
@session.click_button('Upload Single')
expect(@session).to have_content("Content-type: text/csv")
end
end
describe "#click" do