summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/migrate_stage_index_spec.rb
blob: 4db829b1e7bdf1fe652aa689a1bed87534b79b6d (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
require 'spec_helper'

describe Gitlab::BackgroundMigration::MigrateStageIndex, :migration, schema: 20180420080616 do
  let(:namespaces) { table(:namespaces) }
  let(:projects) { table(:projects) }
  let(:pipelines) { table(:ci_pipelines) }
  let(:stages) { table(:ci_stages) }
  let(:jobs) { table(:ci_builds) }

  before do
    namespaces.create(id: 10, name: 'gitlab-org', path: 'gitlab-org')
    projects.create!(id: 11, namespace_id: 10, name: 'gitlab', path: 'gitlab')
    pipelines.create!(id: 12, project_id: 11, ref: 'master', sha: 'adf43c3a')

    stages.create(id: 100, project_id: 11, pipeline_id: 12, name: 'build')
    stages.create(id: 101, project_id: 11, pipeline_id: 12, name: 'test')

    jobs.create!(id: 121, commit_id: 12, project_id: 11,
                 stage_idx: 2, stage_id: 100)
    jobs.create!(id: 122, commit_id: 12, project_id: 11,
                 stage_idx: 2, stage_id: 100)
    jobs.create!(id: 123, commit_id: 12, project_id: 11,
                 stage_idx: 10, stage_id: 100)
    jobs.create!(id: 124, commit_id: 12, project_id: 11,
                 stage_idx: 3, stage_id: 101)
  end

  it 'correctly migrates stages indices' do
    expect(stages.all.pluck(:position)).to all(be_nil)

    described_class.new.perform(100, 101)

    expect(stages.all.order(:id).pluck(:position)).to eq [2, 3]
  end
end