diff options
Diffstat (limited to 'spec/lib/gitlab/import_export/project_tree_restorer_spec.rb')
-rw-r--r-- | spec/lib/gitlab/import_export/project_tree_restorer_spec.rb | 94 |
1 files changed, 46 insertions, 48 deletions
diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index 87be7857e67..676973ff5e7 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -2,6 +2,8 @@ require 'spec_helper' include ImportExport::CommonUtil describe Gitlab::ImportExport::ProjectTreeRestorer do + let(:shared) { project.import_export_shared } + describe 'restore project tree' do before(:context) do # Using an admin for import, so we can check assignment of existing members @@ -14,7 +16,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do RSpec::Mocks.with_temporary_scope do @project = create(:project, :builds_enabled, :issues_disabled, name: 'project', path: 'project') @shared = @project.import_export_shared - allow(@shared).to receive(:export_path).and_return('spec/lib/gitlab/import_export/') + allow(@shared).to receive(:export_path).and_return('spec/fixtures/lib/gitlab/import_export/') allow_any_instance_of(Repository).to receive(:fetch_source_branch!).and_return(true) allow_any_instance_of(Gitlab::Git::Repository).to receive(:branch_exists?).and_return(false) @@ -94,6 +96,17 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do expect(Ci::Pipeline.where(ref: nil)).not_to be_empty end + it 'restores pipeline for merge request' do + pipeline = Ci::Pipeline.find_by_sha('048721d90c449b244b7b4c53a9186b04330174ec') + + expect(pipeline).to be_valid + expect(pipeline.tag).to be_falsey + expect(pipeline.source).to eq('merge_request_event') + expect(pipeline.merge_request.id).to be > 0 + expect(pipeline.merge_request.target_branch).to eq('feature') + expect(pipeline.merge_request.source_branch).to eq('feature_conflict') + end + it 'preserves updated_at on issues' do issue = Issue.where(description: 'Aliquam enim illo et possimus.').first @@ -274,36 +287,6 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do end end - shared_examples 'restores project successfully' do - it 'correctly restores project' do - expect(shared.errors).to be_empty - expect(restored_project_json).to be_truthy - end - end - - shared_examples 'restores project correctly' do |**results| - it 'has labels' do - expect(project.labels.size).to eq(results.fetch(:labels, 0)) - end - - it 'has label priorities' do - expect(project.labels.find_by(title: 'A project label').priorities).not_to be_empty - end - - it 'has milestones' do - expect(project.milestones.size).to eq(results.fetch(:milestones, 0)) - end - - it 'has issues' do - expect(project.issues.size).to eq(results.fetch(:issues, 0)) - end - - it 'does not set params that are excluded from import_export settings' do - expect(project.import_type).to be_nil - expect(project.creator_id).not_to eq 123 - end - end - shared_examples 'restores group correctly' do |**results| it 'has group label' do expect(project.group.labels.size).to eq(results.fetch(:labels, 0)) @@ -322,18 +305,17 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do context 'Light JSON' do let(:user) { create(:user) } - let(:shared) { project.import_export_shared } let!(:project) { create(:project, :builds_disabled, :issues_disabled, name: 'project', path: 'project') } let(:project_tree_restorer) { described_class.new(user: user, shared: shared, project: project) } let(:restored_project_json) { project_tree_restorer.restore } before do - allow(shared).to receive(:export_path).and_return('spec/lib/gitlab/import_export/') + allow(shared).to receive(:export_path).and_return('spec/fixtures/lib/gitlab/import_export/') end context 'with a simple project' do before do - project_tree_restorer.instance_variable_set(:@path, "spec/lib/gitlab/import_export/project.light.json") + project_tree_restorer.instance_variable_set(:@path, "spec/fixtures/lib/gitlab/import_export/project.light.json") restored_project_json end @@ -341,6 +323,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do it_behaves_like 'restores project correctly', issues: 1, labels: 2, + label_with_priorities: 'A project label', milestones: 1, first_issue_labels: 1, services: 1 @@ -363,7 +346,12 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do create(:ci_build, token: 'abcd') end - it_behaves_like 'restores project successfully' + it_behaves_like 'restores project correctly', + issues: 1, + labels: 2, + label_with_priorities: 'A project label', + milestones: 1, + first_issue_labels: 1 end end @@ -430,15 +418,15 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do end before do - project_tree_restorer.instance_variable_set(:@path, "spec/lib/gitlab/import_export/project.group.json") + project_tree_restorer.instance_variable_set(:@path, "spec/fixtures/lib/gitlab/import_export/project.group.json") restored_project_json end - it_behaves_like 'restores project successfully' it_behaves_like 'restores project correctly', issues: 2, labels: 2, + label_with_priorities: 'A project label', milestones: 2, first_issue_labels: 1 @@ -446,6 +434,11 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do labels: 0, milestones: 0, first_issue_labels: 1 + + it 'restores issue states' do + expect(project.issues.with_state(:closed).count).to eq(1) + expect(project.issues.with_state(:opened).count).to eq(1) + end end context 'with existing group models' do @@ -459,7 +452,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do end before do - project_tree_restorer.instance_variable_set(:@path, "spec/lib/gitlab/import_export/project.light.json") + project_tree_restorer.instance_variable_set(:@path, "spec/fixtures/lib/gitlab/import_export/project.light.json") end it 'does not import any templated services' do @@ -501,7 +494,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do end it 'preserves the project milestone IID' do - project_tree_restorer.instance_variable_set(:@path, "spec/lib/gitlab/import_export/project.milestone-iid.json") + project_tree_restorer.instance_variable_set(:@path, "spec/fixtures/lib/gitlab/import_export/project.milestone-iid.json") expect_any_instance_of(Gitlab::ImportExport::Shared).not_to receive(:error) @@ -532,21 +525,21 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do end end - describe '#restored_project' do + context 'Minimal JSON' do let(:project) { create(:project) } - let(:shared) { project.import_export_shared } let(:tree_hash) { { 'visibility_level' => visibility } } let(:restorer) { described_class.new(user: nil, shared: shared, project: project) } before do - restorer.instance_variable_set(:@tree_hash, tree_hash) + expect(restorer).to receive(:read_tree_hash) { tree_hash } end context 'no group visibility' do let(:visibility) { Gitlab::VisibilityLevel::PRIVATE } it 'uses the project visibility' do - expect(restorer.restored_project.visibility_level).to eq(visibility) + expect(restorer.restore).to eq(true) + expect(restorer.project.visibility_level).to eq(visibility) end end @@ -557,7 +550,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do it 'uses private visibility' do stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL]) - expect(restorer.restored_project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) + expect(restorer.restore).to eq(true) + expect(restorer.project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) end end end @@ -574,7 +568,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do let(:visibility) { Gitlab::VisibilityLevel::PUBLIC } it 'uses the group visibility' do - expect(restorer.restored_project.visibility_level).to eq(group_visibility) + expect(restorer.restore).to eq(true) + expect(restorer.project.visibility_level).to eq(group_visibility) end end @@ -583,7 +578,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do let(:visibility) { Gitlab::VisibilityLevel::PRIVATE } it 'uses the project visibility' do - expect(restorer.restored_project.visibility_level).to eq(visibility) + expect(restorer.restore).to eq(true) + expect(restorer.project.visibility_level).to eq(visibility) end end @@ -592,14 +588,16 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do let(:visibility) { Gitlab::VisibilityLevel::PUBLIC } it 'uses the group visibility' do - expect(restorer.restored_project.visibility_level).to eq(group_visibility) + expect(restorer.restore).to eq(true) + expect(restorer.project.visibility_level).to eq(group_visibility) end context 'with restricted internal visibility' do it 'sets private visibility' do stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL]) - expect(restorer.restored_project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) + expect(restorer.restore).to eq(true) + expect(restorer.project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) end end end |