Commit 06e40583 authored by Max Woolf's avatar Max Woolf

Merge branch 'kassio/remove-unnecessary-transform-from-pipeline' into 'master'

BulkImports: Remove unnecessary transform from GroupAvatar

See merge request gitlab-org/gitlab!65578
parents c1e16db6 4fe4383c
...@@ -24,10 +24,6 @@ module BulkImports ...@@ -24,10 +24,6 @@ module BulkImports
BulkImports::Pipeline::ExtractedData.new(data: { filepath: filepath }) BulkImports::Pipeline::ExtractedData.new(data: { filepath: filepath })
end end
def transform(_, data)
data
end
def load(context, data) def load(context, data)
return if data.blank? return if data.blank?
...@@ -44,7 +40,7 @@ module BulkImports ...@@ -44,7 +40,7 @@ module BulkImports
end end
end end
def after_run(context, _) def after_run(_)
FileUtils.remove_entry(context.extra[:tmpdir]) if context.extra[:tmpdir].present? FileUtils.remove_entry(context.extra[:tmpdir]) if context.extra[:tmpdir].present?
end end
end end
......
...@@ -23,47 +23,55 @@ RSpec.describe BulkImports::Groups::Pipelines::GroupAvatarPipeline do ...@@ -23,47 +23,55 @@ RSpec.describe BulkImports::Groups::Pipelines::GroupAvatarPipeline do
subject { described_class.new(context) } subject { described_class.new(context) }
describe '#extract' do describe '#run' do
it 'downloads the group avatar' do it 'updates the group avatar' do
expect_next_instance_of( avatar_path = 'spec/fixtures/dk.png'
BulkImports::FileDownloadService, stub_file_download(
avatar_path,
configuration: context.configuration, configuration: context.configuration,
relative_url: "/groups/source%2Ffull%2Fpath/avatar", relative_url: "/groups/source%2Ffull%2Fpath/avatar",
dir: an_instance_of(String), dir: an_instance_of(String),
file_size_limit: Avatarable::MAXIMUM_FILE_SIZE, file_size_limit: Avatarable::MAXIMUM_FILE_SIZE,
allowed_content_types: described_class::ALLOWED_AVATAR_DOWNLOAD_TYPES allowed_content_types: described_class::ALLOWED_AVATAR_DOWNLOAD_TYPES
) do |downloader| )
expect(downloader).to receive(:execute)
end
subject.run expect { subject.run }.to change(context.group, :avatar)
end
end
describe '#transform' do expect(context.group.avatar.filename).to eq(File.basename(avatar_path))
it 'returns the given data' do
expect(subject.transform(nil, :value)).to eq(:value)
end end
end
describe '#load' do it 'raises an error when the avatar upload fails' do
it 'updates the group avatar' do avatar_path = 'spec/fixtures/aosp_manifest.xml'
avatar_path = 'spec/fixtures/dk.png' stub_file_download(
data = { filepath: fixture_file_upload(avatar_path) } avatar_path,
configuration: context.configuration,
relative_url: "/groups/source%2Ffull%2Fpath/avatar",
dir: an_instance_of(String),
file_size_limit: Avatarable::MAXIMUM_FILE_SIZE,
allowed_content_types: described_class::ALLOWED_AVATAR_DOWNLOAD_TYPES
)
expect { subject.load(context, data) }.to change(group, :avatar) expect_next_instance_of(Gitlab::Import::Logger) do |logger|
expect(logger).to receive(:error)
.with(
bulk_import_id: context.bulk_import.id,
bulk_import_entity_id: context.entity.id,
bulk_import_entity_type: context.entity.source_type,
context_extra: context.extra,
exception_class: "BulkImports::Groups::Pipelines::GroupAvatarPipeline::GroupAvatarLoadingError",
exception_message: "Avatar file format is not supported. Please try one of the following supported formats: image/png, image/jpeg, image/gif, image/bmp, image/tiff, image/vnd.microsoft.icon",
pipeline_class: "BulkImports::Groups::Pipelines::GroupAvatarPipeline",
pipeline_step: :loader
)
end
expect(FileUtils.identical?(avatar_path, group.avatar.file.file)).to eq(true) expect { subject.run }.to change(BulkImports::Failure, :count)
end end
end
it 'raises an error when the avatar upload fails' do def stub_file_download(filepath = 'file/path.png', **params)
avatar_path = 'spec/fixtures/aosp_manifest.xml' expect_next_instance_of(BulkImports::FileDownloadService, params.presence) do |downloader|
data = { filepath: fixture_file_upload(avatar_path) } expect(downloader).to receive(:execute).and_return(filepath)
expect { subject.load(context, data) }.to raise_error(
described_class::GroupAvatarLoadingError,
"Avatar file format is not supported. Please try one of the following supported formats: image/png, image/jpeg, image/gif, image/bmp, image/tiff, image/vnd.microsoft.icon"
)
end end
end end
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