diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-09-28 00:41:24 +0200 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-09-28 01:40:40 +0200 |
commit | 3e309ea70dd3c91a618a0b59b386244d44ec594a (patch) | |
tree | 1388427a0fb8a3d7a4115ce907e788565542d350 | |
parent | 4de93b6a3e4eabd3eae9eb23910c6acd62649cfa (diff) | |
download | gitlab-ce-3e309ea70dd3c91a618a0b59b386244d44ec594a.tar.gz |
Refactor migration specs using ActiveRecord models
-rw-r--r-- | lib/gitlab/background_migration/populate_external_pipeline_source.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/background_migration/populate_external_pipeline_source_spec.rb | 29 |
2 files changed, 18 insertions, 13 deletions
diff --git a/lib/gitlab/background_migration/populate_external_pipeline_source.rb b/lib/gitlab/background_migration/populate_external_pipeline_source.rb index 98eb7f0b897..036fe641757 100644 --- a/lib/gitlab/background_migration/populate_external_pipeline_source.rb +++ b/lib/gitlab/background_migration/populate_external_pipeline_source.rb @@ -42,7 +42,7 @@ module Gitlab .where( 'EXISTS (?) AND NOT EXISTS (?)', Migratable::CommitStatus.of_type('GenericCommitStatus').has_pipeline.select(1), - Migratable::CommitStatus.of_type('Ci::Build').has_pipeline.select(1), + Migratable::CommitStatus.of_type('Ci::Build').has_pipeline.select(1) ) end end 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 d3926ca4e7c..d95077beb59 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 @@ -4,29 +4,34 @@ require 'spec_helper' describe Gitlab::BackgroundMigration::PopulateExternalPipelineSource, :migration, schema: 20180916011959 do let(:migration) { described_class.new } - let(:projects) { table(:projects) } - let(:pipelines) { table(:ci_pipelines) } - let(:statuses) { table(:ci_builds) } - let(:builds) { table(:ci_builds) } - let!(:internal_pipeline) { pipelines.create(id: 1, source: described_class::Migratable::Pipeline.sources[:web]) } - let!(:external_pipeline) { pipelines.create(id: 2, source: nil) } - let!(:second_external_pipeline) { pipelines.create(id: 3, source: nil) } - let!(:status) { statuses.create(id: 1, commit_id: 2, type: 'GenericCommitStatus') } - let!(:build) { builds.create(id: 2, commit_id: 1, type: 'Ci::Build') } + let!(:internal_pipeline) { create(:ci_pipeline, source: Ci::Pipeline.sources[:web]) } + let!(:external_pipeline) do + build(:ci_pipeline, source: Ci::Pipeline.sources[:unknown]) + .tap { |pipeline| pipeline.save(validate: false) } + end + let!(:second_external_pipeline) do + build(:ci_pipeline, source: Ci::Pipeline.sources[:unknown]) + .tap { |pipeline| pipeline.save(validate: false) } + end + + before do + create(:generic_commit_status, pipeline: external_pipeline) + create(:ci_build, pipeline: internal_pipeline) + end - subject { migration.perform(1, 2) } + subject { migration.perform(external_pipeline.id, second_external_pipeline.id) } it 'populates the pipeline source' do subject - expect(external_pipeline.reload.source).to eq(described_class::Migratable::Pipeline.sources[:external]) + expect(external_pipeline.reload.source).to eq('external') end it 'only processes a single batch of links at a time' do subject - expect(second_external_pipeline.reload.source).to eq(nil) + expect(second_external_pipeline.reload.source).to eq('unknown') end it 'can be repeated without effect' do |