Refactor migration specs using ActiveRecord models
This commit is contained in:
parent
4de93b6a3e
commit
3e309ea70d
2 changed files with 18 additions and 13 deletions
|
@ -42,7 +42,7 @@ module Gitlab
|
||||||
.where(
|
.where(
|
||||||
'EXISTS (?) AND NOT EXISTS (?)',
|
'EXISTS (?) AND NOT EXISTS (?)',
|
||||||
Migratable::CommitStatus.of_type('GenericCommitStatus').has_pipeline.select(1),
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,29 +4,34 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Gitlab::BackgroundMigration::PopulateExternalPipelineSource, :migration, schema: 20180916011959 do
|
describe Gitlab::BackgroundMigration::PopulateExternalPipelineSource, :migration, schema: 20180916011959 do
|
||||||
let(:migration) { described_class.new }
|
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!(:internal_pipeline) { create(:ci_pipeline, source: Ci::Pipeline.sources[:web]) }
|
||||||
let!(:external_pipeline) { pipelines.create(id: 2, source: nil) }
|
let!(:external_pipeline) do
|
||||||
let!(:second_external_pipeline) { pipelines.create(id: 3, source: nil) }
|
build(:ci_pipeline, source: Ci::Pipeline.sources[:unknown])
|
||||||
let!(:status) { statuses.create(id: 1, commit_id: 2, type: 'GenericCommitStatus') }
|
.tap { |pipeline| pipeline.save(validate: false) }
|
||||||
let!(:build) { builds.create(id: 2, commit_id: 1, type: 'Ci::Build') }
|
end
|
||||||
|
let!(:second_external_pipeline) do
|
||||||
|
build(:ci_pipeline, source: Ci::Pipeline.sources[:unknown])
|
||||||
|
.tap { |pipeline| pipeline.save(validate: false) }
|
||||||
|
end
|
||||||
|
|
||||||
subject { migration.perform(1, 2) }
|
before do
|
||||||
|
create(:generic_commit_status, pipeline: external_pipeline)
|
||||||
|
create(:ci_build, pipeline: internal_pipeline)
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { migration.perform(external_pipeline.id, second_external_pipeline.id) }
|
||||||
|
|
||||||
it 'populates the pipeline source' do
|
it 'populates the pipeline source' do
|
||||||
subject
|
subject
|
||||||
|
|
||||||
expect(external_pipeline.reload.source).to eq(described_class::Migratable::Pipeline.sources[:external])
|
expect(external_pipeline.reload.source).to eq('external')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'only processes a single batch of links at a time' do
|
it 'only processes a single batch of links at a time' do
|
||||||
subject
|
subject
|
||||||
|
|
||||||
expect(second_external_pipeline.reload.source).to eq(nil)
|
expect(second_external_pipeline.reload.source).to eq('unknown')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can be repeated without effect' do
|
it 'can be repeated without effect' do
|
||||||
|
|
Loading…
Reference in a new issue