Commit 48b0bc33 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix specs for retry build after making stages unique

parent 4e4ee368
module Ci module Ci
class RetryBuildService < ::BaseService class RetryBuildService < ::BaseService
CLONE_ACCESSORS = %i[pipeline project ref tag options commands name CLONE_ACCESSORS = %i[pipeline project ref tag options commands name
allow_failure stage_id stage stage_idx trigger_request allow_failure stage stage_id stage_idx trigger_request
yaml_variables when environment coverage_regex yaml_variables when environment coverage_regex
description tag_list protected].freeze description tag_list protected].freeze
......
...@@ -5,7 +5,11 @@ describe Ci::RetryBuildService do ...@@ -5,7 +5,11 @@ describe Ci::RetryBuildService do
set(:project) { create(:project) } set(:project) { create(:project) }
set(:pipeline) { create(:ci_pipeline, project: project) } set(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, pipeline: pipeline) } let(:stage) do
Ci::Stage.create!(project: project, pipeline: pipeline, name: 'test')
end
let(:build) { create(:ci_build, pipeline: pipeline, stage_id: stage.id) }
let(:service) do let(:service) do
described_class.new(project, user) described_class.new(project, user)
...@@ -26,29 +30,27 @@ describe Ci::RetryBuildService do ...@@ -26,29 +30,27 @@ describe Ci::RetryBuildService do
user_id auto_canceled_by_id retried failure_reason].freeze user_id auto_canceled_by_id retried failure_reason].freeze
shared_examples 'build duplication' do shared_examples 'build duplication' do
let(:stage) do let(:another_pipeline) { create(:ci_empty_pipeline, project: project) }
# TODO, we still do not have factory for new stages, we will need to
# switch existing factory to persist stages, instead of using LegacyStage
#
Ci::Stage.create!(project: project, pipeline: pipeline, name: 'test')
end
let(:build) do let(:build) do
create(:ci_build, :failed, :artifacts, :expired, :erased, create(:ci_build, :failed, :artifacts, :expired, :erased,
:queued, :coverage, :tags, :allowed_to_fail, :on_tag, :queued, :coverage, :tags, :allowed_to_fail, :on_tag,
:triggered, :trace, :teardown_environment, :triggered, :trace, :teardown_environment,
description: 'my-job', stage: 'test', pipeline: pipeline, description: 'my-job', stage: 'test', stage_id: stage.id,
auto_canceled_by: create(:ci_empty_pipeline, project: project)) do |build| pipeline: pipeline, auto_canceled_by: another_pipeline)
##
# TODO, workaround for FactoryBot limitation when having both
# stage (text) and stage_id (integer) columns in the table.
build.stage_id = stage.id
end end
before do
# Make sure that build has both `stage_id` and `stage` because FactoryBot
# can reset one of the fields when assigning another. We plan to deprecate
# and remove legacy `stage` column in the future.
build.update_attributes(stage: 'test', stage_id: stage.id)
end end
describe 'clone accessors' do describe 'clone accessors' do
CLONE_ACCESSORS.each do |attribute| CLONE_ACCESSORS.each do |attribute|
it "clones #{attribute} build attribute" do it "clones #{attribute} build attribute" do
expect(build.send(attribute)).not_to be_nil
expect(new_build.send(attribute)).not_to be_nil expect(new_build.send(attribute)).not_to be_nil
expect(new_build.send(attribute)).to eq build.send(attribute) expect(new_build.send(attribute)).to eq build.send(attribute)
end end
...@@ -121,10 +123,12 @@ describe Ci::RetryBuildService do ...@@ -121,10 +123,12 @@ describe Ci::RetryBuildService do
context 'when there are subsequent builds that are skipped' do context 'when there are subsequent builds that are skipped' do
let!(:subsequent_build) do let!(:subsequent_build) do
create(:ci_build, :skipped, stage_idx: 1, pipeline: pipeline) create(:ci_build, :skipped, stage_idx: 2,
pipeline: pipeline,
stage: 'deploy')
end end
it 'resumes pipeline processing in subsequent stages' do it 'resumes pipeline processing in a subsequent stage' do
service.execute(build) service.execute(build)
expect(subsequent_build.reload).to be_created expect(subsequent_build.reload).to be_created
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment