diff options
Diffstat (limited to 'spec/lib/gitlab/import_export/project')
3 files changed, 104 insertions, 15 deletions
diff --git a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb index 7252457849e..5e9fed32c4e 100644 --- a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb @@ -172,6 +172,10 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_ it 'has preloaded target project' do expect(created_object.target_project).to equal(project) end + + it 'has MWPS set to false' do + expect(created_object.merge_when_pipeline_succeeds).to eq(false) + end end context 'issue object' do @@ -297,6 +301,38 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_ end end + context 'pipeline setup' do + let(:relation_sym) { :ci_pipelines } + let(:relation_hash) do + { + "id" => 1, + "status" => status + } + end + + subject { created_object } + + ::Ci::HasStatus::COMPLETED_STATUSES.each do |status| + context "when relation_hash has a completed status of #{status}}" do + let(:status) { status } + + it "does not change the created object status" do + expect(created_object.status).to eq(status) + end + end + end + + ::Ci::HasStatus::CANCELABLE_STATUSES.each do |status| + context "when relation_hash has cancelable status of #{status}}" do + let(:status) { status } + + it "sets the created object status to canceled" do + expect(created_object.status).to eq('canceled') + end + end + end + end + context 'pipeline_schedule' do let(:relation_sym) { :pipeline_schedules } let(:relation_hash) do 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 47003707172..60403001b72 100644 --- a/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb @@ -135,6 +135,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer, feature_category: :i 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') + expect(pipeline.merge_request.merge_when_pipeline_succeeds).to eq(false) end it 'restores pipelines based on ascending id order' do @@ -146,6 +147,9 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer, feature_category: :i 5f923865dde3436854e9ceb9cdb7815618d4e849 d2d430676773caa88cdaf7c55944073b2fd5561a 2ea1f3dec713d940208fb5ce4a38765ecb5d3f73 + 1b6c4f044c63217d1ed06e514c84d22871bed912 + ded178474ef2ba1f80a9964ba15da3ddb3cf664b + fd459e5c514d70dc525c5e70990ca5e0debb3105 ] project = Project.find_by_path('project') @@ -297,6 +301,12 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer, feature_category: :i end end + it 'sets MWPS to false for all merge requests' do + MergeRequest.find_each do |merge_request| + expect(merge_request.merge_when_pipeline_succeeds).to eq(false) + end + end + it 'has multiple merge request assignees' do expect(MergeRequest.find_by(title: 'MR1').assignees).to contain_exactly(@user, *@existing_members) expect(MergeRequest.find_by(title: 'MR2').assignees).to be_empty @@ -545,9 +555,9 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer, feature_category: :i end it 'has the correct number of pipelines and statuses' do - expect(@project.ci_pipelines.size).to eq(7) + expect(@project.ci_pipelines.size).to eq(10) - @project.ci_pipelines.order(:id).zip([2, 0, 2, 3, 2, 2, 0]) + @project.ci_pipelines.order(:id).zip([2, 0, 2, 3, 2, 8, 0, 0, 0, 0]) .each do |(pipeline, expected_status_size)| expect(pipeline.statuses.size).to eq(expected_status_size) end @@ -555,28 +565,58 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer, feature_category: :i end context 'when restoring hierarchy of pipeline, stages and jobs' do - it 'restores pipelines' do - expect(Ci::Pipeline.all.count).to be 7 - end + context 'pipelines' do + it 'restores pipelines' do + expect(Ci::Pipeline.all.count).to be 10 + end - it 'restores pipeline stages' do - expect(Ci::Stage.all.count).to be 6 + it 'marks cancelable pipelines as canceled' do + expect(Ci::Pipeline.where(status: 'canceled').count).to eq 7 + end end - it 'correctly restores association between stage and a pipeline' do - expect(Ci::Stage.all).to all(have_attributes(pipeline_id: a_value > 0)) + context 'stages' do + it 'restores pipeline stages' do + expect(Ci::Stage.all.count).to be 7 + end + + it 'marks cancelable stages as canceled' do + expect(Ci::Stage.where(status: 'canceled').count).to eq 6 + end + + it 'correctly restores association between stage and a pipeline' do + expect(Ci::Stage.all).to all(have_attributes(pipeline_id: a_value > 0)) + end end - it 'restores builds' do - expect(Ci::Build.all.count).to be 7 + context 'builds' do + it 'restores builds' do + expect(Ci::Build.all.count).to be 7 + end + + it 'marks cancelable builds as canceled' do + expect(Ci::Build.where(status: 'canceled').count).to eq 3 + end end - it 'restores bridges' do - expect(Ci::Bridge.all.count).to be 1 + context 'bridges' do + it 'restores bridges' do + expect(Ci::Bridge.all.count).to be 5 + end + + it 'marks cancelable bridges as canceled' do + expect(Ci::Bridge.where(status: 'canceled').count).to eq 4 + end end - it 'restores generic commit statuses' do - expect(GenericCommitStatus.all.count).to be 1 + context 'generic commit statuses' do + it 'restores generic commit statuses' do + expect(GenericCommitStatus.all.count).to be 3 + end + + it 'marks cancelable generic commit statuses as canceled' do + expect(GenericCommitStatus.where(status: 'canceled').count).to eq 2 + end end it 'correctly restores association between a stage and a job' do diff --git a/spec/lib/gitlab/import_export/project/tree_saver_spec.rb b/spec/lib/gitlab/import_export/project/tree_saver_spec.rb index aa8290d7a05..abb781b277b 100644 --- a/spec/lib/gitlab/import_export/project/tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/project/tree_saver_spec.rb @@ -127,6 +127,10 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver, :with_license, feature_ expect(system_notes.size).to eq(1) expect(system_notes.first['note']).to eq('merged') end + + it 'has no merge_when_pipeline_succeeds' do + expect(subject.first['merge_when_pipeline_succeeds']).to be_nil + end end context 'with snippets' do @@ -301,6 +305,14 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver, :with_license, feature_ it { is_expected.not_to be_empty } end + + context 'with pipeline schedules' do + let(:relation_name) { :pipeline_schedules } + + it 'has no owner_id' do + expect(subject.first['owner_id']).to be_nil + end + end end describe '#saves project tree' do @@ -535,6 +547,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver, :with_license, feature_ design = create(:design, :with_file, versions_count: 2, issue: issue) create(:diff_note_on_design, noteable: design, project: project, author: user) + create(:ci_pipeline_schedule, project: project, owner: user) project end |