summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/populate_external_pipeline_source_spec.rb
blob: 05a95cb5ba4e4efe8c7f798ae126d6a728b56776 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::BackgroundMigration::PopulateExternalPipelineSource, :migration, schema: 20180916011959 do
  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!(:external_pipeline) do
    build(:ci_pipeline, source: :unknown)
      .tap { |pipeline| pipeline.save(validate: false) }
  end
  let!(:second_external_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)
  end

  subject { migration.perform(pipelines.min, pipelines.max) }

  it 'populates the pipeline source' do
    subject

    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('unknown')
  end

  it 'can be repeated without effect' do
    subject

    expect { subject }.not_to change { external_pipeline.reload.source }
  end
end