diff options
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/import_export/importer_spec.rb | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/spec/lib/gitlab/import_export/importer_spec.rb b/spec/lib/gitlab/import_export/importer_spec.rb index d75416f2a62..991e354f499 100644 --- a/spec/lib/gitlab/import_export/importer_spec.rb +++ b/spec/lib/gitlab/import_export/importer_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe Gitlab::ImportExport::Importer do + let(:user) { create(:user) } let(:test_path) { "#{Dir.tmpdir}/importer_spec" } let(:shared) { project.import_export_shared } let(:project) { create(:project, import_source: File.join(test_path, 'exported-project.gz')) } @@ -11,6 +12,7 @@ describe Gitlab::ImportExport::Importer do allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(test_path) FileUtils.mkdir_p(shared.export_path) FileUtils.cp(Rails.root.join('spec', 'fixtures', 'exported-project.gz'), test_path) + allow(subject).to receive(:remove_import_file) end after do @@ -42,7 +44,8 @@ describe Gitlab::ImportExport::Importer do Gitlab::ImportExport::RepoRestorer, Gitlab::ImportExport::WikiRestorer, Gitlab::ImportExport::UploadsRestorer, - Gitlab::ImportExport::LfsRestorer + Gitlab::ImportExport::LfsRestorer, + Gitlab::ImportExport::StatisticsRestorer ].each do |restorer| it "calls the #{restorer}" do fake_restorer = double(restorer.to_s) @@ -60,5 +63,42 @@ describe Gitlab::ImportExport::Importer do importer.execute end end + + context 'when project successfully restored' do + let!(:existing_project) { create(:project, namespace: user.namespace) } + let(:project) { create(:project, namespace: user.namespace, name: 'whatever', path: 'whatever') } + + before do + restorers = double + + allow(subject).to receive(:import_file).and_return(true) + allow(subject).to receive(:check_version!).and_return(true) + allow(subject).to receive(:restorers).and_return(restorers) + allow(restorers).to receive(:all?).and_return(true) + allow(project).to receive(:import_data).and_return(double(data: { 'original_path' => existing_project.path })) + end + + context 'when import_data' do + context 'has original_path' do + it 'overwrites existing project' do + expect_any_instance_of(::Projects::OverwriteProjectService).to receive(:execute).with(existing_project) + + subject.execute + end + end + + context 'has not original_path' do + before do + allow(project).to receive(:import_data).and_return(double(data: {})) + end + + it 'does not call the overwrite service' do + expect_any_instance_of(::Projects::OverwriteProjectService).not_to receive(:execute).with(existing_project) + + subject.execute + end + end + end + end end end |