debian-mirror-gitlab/spec/lib/gitlab/import_export/avatar_restorer_spec.rb

45 lines
1.2 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Gitlab::ImportExport::AvatarRestorer do
2017-08-17 22:00:37 +05:30
include UploadHelpers
2018-03-27 19:54:05 +05:30
let(:shared) { project.import_export_shared }
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2016-08-24 12:49:21 +05:30
after do
project.remove_avatar!
end
2018-11-20 20:47:30 +05:30
context 'with avatar' do
before do
2020-01-01 13:55:28 +05:30
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:avatar_export_file).and_return(uploaded_image_temp_path)
end
2018-11-20 20:47:30 +05:30
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
2016-08-24 12:49:21 +05:30
end
2018-11-20 20:47:30 +05:30
it 'does not break if there is just a directory' do
Dir.mktmpdir do |tmpdir|
FileUtils.mkdir_p("#{tmpdir}/a/b")
2020-01-01 13:55:28 +05:30
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:avatar_export_path).and_return("#{tmpdir}/a")
end
2016-08-24 12:49:21 +05:30
2018-11-20 20:47:30 +05:30
expect(described_class.new(project: project, shared: shared).restore).to be true
end
2016-08-24 12:49:21 +05:30
end
end