diff options
| author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-05-26 14:46:45 +0200 |
|---|---|---|
| committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-05-26 14:46:45 +0200 |
| commit | 918ababba6fce694c61d54bb2ff6983a886f696a (patch) | |
| tree | 1d502368d29711fb4c2fae814b4fb99bb8ca4bfe /spec/migrations | |
| parent | 0f9fbae78a51f7bf4df50d96060087e1cf903b05 (diff) | |
| download | gitlab-ce-918ababba6fce694c61d54bb2ff6983a886f696a.tar.gz | |
Add pipeline stages post deployment migration
Diffstat (limited to 'spec/migrations')
| -rw-r--r-- | spec/migrations/migrate_pipeline_stages_spec.rb | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/spec/migrations/migrate_pipeline_stages_spec.rb b/spec/migrations/migrate_pipeline_stages_spec.rb index 4a469174b9e..9cf13a1dabc 100644 --- a/spec/migrations/migrate_pipeline_stages_spec.rb +++ b/spec/migrations/migrate_pipeline_stages_spec.rb @@ -1,19 +1,49 @@ require 'spec_helper' -require Rails.root.join('db', 'migrate', '20170525132202_migrate_pipeline_stages.rb') +require Rails.root.join('db', 'post_migrate', '20170526101042_migrate_pipeline_stages.rb') -describe MigratePipelineStages, :migration, schema: 20170523091700 do +describe MigratePipelineStages, :migration, schema: 20170525132202 do ## - # Create test data + # Create test data - pipeline and CI/CD jobs. # + + let(:jobs) { table(:ci_builds) } + let(:stages) { table(:ci_stages) } + let(:pipelines) { table(:ci_pipelines) } + before do - table(:ci_pipelines).create!(ref: 'master', sha: 'adf43c3a') + # Create CI/CD pipelines + # + pipelines.create!(id: 1, project_id: 123, ref: 'master', sha: 'adf43c3a') + pipelines.create!(id: 2, project_id: 456, ref: 'feature', sha: '21a3deb') + + # Create CI/CD jobs + # + jobs.create!(id: 1, commit_id: 1, project_id: 123, stage_idx: 2, stage: 'build') + jobs.create!(id: 2, commit_id: 1, project_id: 123, stage_idx: 2, stage: 'build') + jobs.create!(id: 3, commit_id: 1, project_id: 123, stage_idx: 1, stage: 'test') + jobs.create!(id: 4, commit_id: 1, project_id: 123, stage_idx: 1, stage: 'test') + jobs.create!(id: 5, commit_id: 1, project_id: 123, stage_idx: 3, stage: 'deploy') + jobs.create!(id: 6, commit_id: 2, project_id: 456, stage_idx: 3, stage: 'deploy') + jobs.create!(id: 7, commit_id: 2, project_id: 456, stage_idx: 2, stage: 'test:2') + jobs.create!(id: 8, commit_id: 2, project_id: 456, stage_idx: 1, stage: 'test:1') + jobs.create!(id: 9, commit_id: 2, project_id: 456, stage_idx: 1, stage: 'test:1') + jobs.create!(id: 10, commit_id: 2, project_id: 456, stage_idx: 2, stage: 'test:2') + jobs.create!(id: 11, commit_id: 3, project_id: 789, stage_idx: 3, stage: 'deploy') end - it 'correctly migrates pipeline stages' do |migration, meta| - expect(ActiveRecord::Base.connection.table_exists?('ci_stages')).to eq false + it 'correctly migrates pipeline stages' do + expect(stages.count).to be_zero migrate! - expect(ActiveRecord::Base.connection.table_exists?('ci_stages')).to eq true + expect(stages.count).to eq 7 + expect(stages.all.pluck(:name)) + .to match_array %w[test build deploy test:1 test:2 deploy deploy] + expect(stages.where(pipeline_id: 1).order(:id).pluck(:name)) + .to eq %w[test build deploy] + expect(stages.where(pipeline_id: 2).order(:id).pluck(:name)) + .to eq %w[test:1 test:2 deploy] + + expect(jobs.where(stage_id: nil)).to be_empty end end |
