fix avatar restorer

This commit is contained in:
James Lopez 2018-09-11 08:59:14 +02:00
parent 6e394c44d5
commit 994d91883b
No known key found for this signature in database
GPG key ID: 756BF8E9D7C0CF39
2 changed files with 24 additions and 11 deletions

View file

@ -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}/**/*"].reject { |f| File.directory?(f) }.first
end end
def avatar_export_path def avatar_export_path

View file

@ -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
@ -25,3 +26,15 @@ 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 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