Commit d6b691a4 authored by GitLab Bot's avatar GitLab Bot

Merge remote-tracking branch 'upstream/master' into ce-to-ee-2018-09-11

parents 047b9072 c56f2b96
...@@ -19,7 +19,7 @@ class AvatarUploader < GitlabUploader ...@@ -19,7 +19,7 @@ class AvatarUploader < GitlabUploader
end end
def absolute_path def absolute_path
self.class.absolute_path(model.avatar) self.class.absolute_path(model.avatar.upload)
end end
private private
......
---
title: Fix broken exports when they include a projet avatar
merge_request: 21649
author:
type: fixed
...@@ -19,7 +19,7 @@ module Gitlab ...@@ -19,7 +19,7 @@ module Gitlab
private private
def avatar_export_file def avatar_export_file
@avatar_export_file ||= Dir["#{avatar_export_path}/**/*"].first @avatar_export_file ||= Dir["#{avatar_export_path}/**/*"].find { |f| File.file?(f) }
end end
def avatar_export_path def avatar_export_path
......
...@@ -6,15 +6,16 @@ describe Gitlab::ImportExport::AvatarRestorer do ...@@ -6,15 +6,16 @@ describe Gitlab::ImportExport::AvatarRestorer do
let(:shared) { project.import_export_shared } let(:shared) { project.import_export_shared }
let(:project) { create(:project) } let(:project) { create(:project) }
after do
project.remove_avatar!
end
context 'with avatar' do
before do before do
allow_any_instance_of(described_class).to receive(:avatar_export_file) allow_any_instance_of(described_class).to receive(:avatar_export_file)
.and_return(uploaded_image_temp_path) .and_return(uploaded_image_temp_path)
end end
after do
project.remove_avatar!
end
it 'restores a project avatar' do it 'restores a project avatar' do
expect(described_class.new(project: project, shared: shared).restore).to be true expect(described_class.new(project: project, shared: shared).restore).to be true
end end
...@@ -24,4 +25,16 @@ describe Gitlab::ImportExport::AvatarRestorer do ...@@ -24,4 +25,16 @@ describe Gitlab::ImportExport::AvatarRestorer do
expect(project.reload.avatar.file.exists?).to be true expect(project.reload.avatar.file.exists?).to be true
end end
end
it 'does not break if there is just a directory' do
Dir.mktmpdir do |tmpdir|
FileUtils.mkdir_p("#{tmpdir}/a/b")
allow_any_instance_of(described_class).to receive(:avatar_export_path)
.and_return("#{tmpdir}/a")
expect(described_class.new(project: project, shared: shared).restore).to be true
end
end
end end
...@@ -35,5 +35,13 @@ describe AvatarUploader do ...@@ -35,5 +35,13 @@ describe AvatarUploader do
it_behaves_like "migrates", to_store: described_class::Store::REMOTE it_behaves_like "migrates", to_store: described_class::Store::REMOTE
it_behaves_like "migrates", from_store: described_class::Store::REMOTE, to_store: described_class::Store::LOCAL it_behaves_like "migrates", from_store: described_class::Store::REMOTE, to_store: described_class::Store::LOCAL
it 'sets the right absolute path' do
storage_path = Gitlab.config.uploads.storage_path
absolute_path = File.join(storage_path, upload.path)
expect(uploader.absolute_path.scan(storage_path).size).to eq(1)
expect(uploader.absolute_path).to eq(absolute_path)
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