mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Work around mime-types broken sorting on MIME::Types.type_for('xxx.csv')
This commit is contained in:
parent
2c910e7f9a
commit
e0e187cbea
3 changed files with 11 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
|
||||
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
1
spec/fixtures/capybara.csv
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
test, mime-type, 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
|
||||
|
|
Loading…
Reference in a new issue