From eac01d4f658be7b4f5a857c54700a685ada8d1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Sat, 29 Sep 2018 00:11:06 +0200 Subject: Reorganize background_migration specs This also adds specs for 3 distinct situations: 2. When there is an unknown pipeline with just a build 3. When there is an unknown pipeline with no statuses 1. When there is an unknown pipeline with a build and a status --- .../populate_external_pipeline_source_spec.rb | 56 ++++++++++++++-------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/spec/lib/gitlab/background_migration/populate_external_pipeline_source_spec.rb b/spec/lib/gitlab/background_migration/populate_external_pipeline_source_spec.rb index 05a95cb5ba4..c7b272cd6ca 100644 --- a/spec/lib/gitlab/background_migration/populate_external_pipeline_source_spec.rb +++ b/spec/lib/gitlab/background_migration/populate_external_pipeline_source_spec.rb @@ -6,39 +6,57 @@ describe Gitlab::BackgroundMigration::PopulateExternalPipelineSource, :migration let(:migration) { described_class.new } let!(:internal_pipeline) { create(:ci_pipeline, source: :web) } - let(:pipelines) { [internal_pipeline, external_pipeline, second_external_pipeline].map(&:id) } + let(:pipelines) { [internal_pipeline, unknown_pipeline].map(&:id) } - let!(:external_pipeline) do - build(:ci_pipeline, source: :unknown) - .tap { |pipeline| pipeline.save(validate: false) } - end - let!(:second_external_pipeline) do + let!(:unknown_pipeline) do build(:ci_pipeline, source: :unknown) .tap { |pipeline| pipeline.save(validate: false) } end - before do - create(:generic_commit_status, pipeline: external_pipeline) - create(:ci_build, pipeline: internal_pipeline) + subject { migration.perform(pipelines.min, pipelines.max) } + + shared_examples 'no changes' do + it 'does not change the pipeline source' do + expect { subject }.not_to change { unknown_pipeline.reload.source } + end end - subject { migration.perform(pipelines.min, pipelines.max) } + context 'when unknown pipeline is external' do + before do + create(:generic_commit_status, pipeline: unknown_pipeline) + end + + it 'populates the pipeline source' do + subject + + expect(unknown_pipeline.reload.source).to eq('external') + end - it 'populates the pipeline source' do - subject + it 'can be repeated without effect' do + subject - expect(external_pipeline.reload.source).to eq('external') + expect { subject }.not_to change { unknown_pipeline.reload.source } + end end - it 'only processes a single batch of links at a time' do - subject + context 'when unknown pipeline has just a build' do + before do + create(:ci_build, pipeline: unknown_pipeline) + end + + it_behaves_like 'no changes' + end - expect(second_external_pipeline.reload.source).to eq('unknown') + context 'when unknown pipeline has no statuses' do + it_behaves_like 'no changes' end - it 'can be repeated without effect' do - subject + context 'when unknown pipeline has a build and a status' do + before do + create(:generic_commit_status, pipeline: unknown_pipeline) + create(:ci_build, pipeline: unknown_pipeline) + end - expect { subject }.not_to change { external_pipeline.reload.source } + it_behaves_like 'no changes' end end -- cgit v1.2.1