Inject ::UploadedFile from Multipart middleware
I mistakenly concluded Rack::Multipart injects File instances into the params. These should be UploadedFile instances. This reuses a mock UploadedFile class we already had in GitLab.
This commit is contained in:
parent
46920f7e37
commit
4ec259fd36
2 changed files with 9 additions and 5 deletions
|
@ -42,7 +42,7 @@ module Gitlab
|
|||
|
||||
key, value = parsed_field.first
|
||||
if value.nil?
|
||||
value = File.open(tmp_path)
|
||||
value = open_file(tmp_path)
|
||||
@open_files << value
|
||||
else
|
||||
value = decorate_params_value(value, @request.params[key], tmp_path)
|
||||
|
@ -68,7 +68,7 @@ module Gitlab
|
|||
|
||||
case path_value
|
||||
when nil
|
||||
value_hash[path_key] = File.open(tmp_path)
|
||||
value_hash[path_key] = open_file(tmp_path)
|
||||
@open_files << value_hash[path_key]
|
||||
value_hash
|
||||
when Hash
|
||||
|
@ -78,6 +78,10 @@ module Gitlab
|
|||
raise "unexpected path value: #{path_value.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
def open_file(path)
|
||||
::UploadedFile.new(path, File.basename(path), 'application/octet-stream')
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(app)
|
||||
|
|
|
@ -12,7 +12,7 @@ describe Gitlab::Middleware::Multipart do
|
|||
|
||||
expect(app).to receive(:call) do |env|
|
||||
file = Rack::Request.new(env).params['file']
|
||||
expect(file).to be_a(File)
|
||||
expect(file).to be_a(::UploadedFile)
|
||||
expect(file.path).to eq(tempfile.path)
|
||||
end
|
||||
|
||||
|
@ -39,7 +39,7 @@ describe Gitlab::Middleware::Multipart do
|
|||
|
||||
expect(app).to receive(:call) do |env|
|
||||
file = Rack::Request.new(env).params['user']['avatar']
|
||||
expect(file).to be_a(File)
|
||||
expect(file).to be_a(::UploadedFile)
|
||||
expect(file.path).to eq(tempfile.path)
|
||||
end
|
||||
|
||||
|
@ -54,7 +54,7 @@ describe Gitlab::Middleware::Multipart do
|
|||
|
||||
expect(app).to receive(:call) do |env|
|
||||
file = Rack::Request.new(env).params['project']['milestone']['themesong']
|
||||
expect(file).to be_a(File)
|
||||
expect(file).to be_a(::UploadedFile)
|
||||
expect(file.path).to eq(tempfile.path)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue