Commit 994d9188 authored by James Lopez's avatar James Lopez

fix avatar restorer

parent 6e394c44
...@@ -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}/**/*"].reject { |f| File.directory?(f) }.first
end end
def avatar_export_path def avatar_export_path
......
...@@ -6,22 +6,35 @@ describe Gitlab::ImportExport::AvatarRestorer do ...@@ -6,22 +6,35 @@ 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) }
before do
allow_any_instance_of(described_class).to receive(:avatar_export_file)
.and_return(uploaded_image_temp_path)
end
after do after do
project.remove_avatar! project.remove_avatar!
end end
it 'restores a project avatar' do context 'with avatar' do
expect(described_class.new(project: project, shared: shared).restore).to be true before do
allow_any_instance_of(described_class).to receive(:avatar_export_file)
.and_return(uploaded_image_temp_path)
end
it 'restores a project avatar' do
expect(described_class.new(project: project, shared: shared).restore).to be true
end
it 'saves the avatar into the project' do
described_class.new(project: project, shared: shared).restore
expect(project.reload.avatar.file.exists?).to be true
end
end end
it 'saves the avatar into the project' do it 'does not break if there is just a directory' do
described_class.new(project: project, shared: shared).restore 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(project.reload.avatar.file.exists?).to be true expect(described_class.new(project: project, shared: shared).restore).to be true
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