Commit abd78e4d authored by Alex Kalderimis's avatar Alex Kalderimis

Add unique_file class method to FileUpload

This encapsulates the logic for loading a fixture and assigning a new
unique name (with the same extension) into a single method.
parent fdc2417f
......@@ -13,10 +13,6 @@ describe Mutations::DesignManagement::Upload do
described_class.new(object: nil, context: { current_user: user }, field: nil)
end
def unique_file(upload)
::Gitlab::FileUpload.new(upload).tap { |f| f.original_filename = generate(:jpeg_file) }
end
def run_mutation(files_to_upload = files, project_path = project.full_path, iid = issue.iid)
mutation = described_class.new(object: nil, context: { current_user: user }, field: nil)
mutation.resolve(project_path: project_path, iid: iid, files: files_to_upload)
......@@ -53,7 +49,7 @@ describe Mutations::DesignManagement::Upload do
['dk.png', 'rails_sample.jpg', 'banana_sample.gif']
.cycle
.take(Concurrent.processor_count * 2)
.map { |f| unique_file(fixture_file_upload("spec/fixtures/#{f}")) }
.map { |f| RenameableUpload.unique_file(f) }
end
def creates_designs
......
......@@ -21,7 +21,6 @@ describe DesignManagement::SaveDesignsService do
before do
project.add_developer(developer)
# allow(::DesignManagement::NewVersionWorker).to receive(:perform_async)
end
def run_service(files_to_upload = nil)
......@@ -101,10 +100,10 @@ describe DesignManagement::SaveDesignsService do
it 'can run the same command in parallel' do
blocks = Array.new(10).map do
wrapped_files = files.map { |f| Gitlab::FileUpload.new(f) }
wrapped_files.each { |f| f.original_filename = generate(:jpeg_file) }
unique_files = %w(rails_sample.jpg dk.png)
.map { |name| RenameableUpload.unique_file(name) }
-> { run_service(wrapped_files) }
-> { run_service(unique_files) }
end
expect { run_parallel(blocks) }.to change(DesignManagement::Version, :count).by(10)
......
# frozen_string_literal: true
class Gitlab::FileUpload < SimpleDelegator
attr_accessor :original_filename
end
# frozen_string_literal: true
class RenameableUpload < SimpleDelegator
attr_accessor :original_filename
# Get a fixture file with a new unique name, and the same extension
def self.unique_file(name)
upload = new(fixture_file_upload("spec/fixtures/#{name}"))
ext = File.extname(name)
new_name = File.basename(FactoryBot.generate(:filename), '.*')
upload.original_filename = new_name + ext
upload
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment