From 658c5f32a3eac2f4a478e84ad767ba000041b461 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 15 Feb 2017 16:04:05 +0100 Subject: [PATCH] Add test for cloning attributes when retrying a build --- spec/services/ci/retry_build_service_spec.rb | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spec/services/ci/retry_build_service_spec.rb b/spec/services/ci/retry_build_service_spec.rb index b7e0308f033..d3cc9fea4df 100644 --- a/spec/services/ci/retry_build_service_spec.rb +++ b/spec/services/ci/retry_build_service_spec.rb @@ -10,6 +10,34 @@ describe Ci::RetryBuildService, :services do described_class.new(project, user) end + shared_examples 'build duplication' do + let(:build) do + create(:ci_build, :failed, :artifacts, + pipeline: pipeline, + coverage: 90.0, + coverage_regex: '/(d+)/') + end + + it 'clones expected attributes' do + clone_attributes = %w[ref tag project pipeline options commands tag_list + name allow_failure stage stage_idx trigger_request + yaml_variables when environment coverage_regex] + + clone_attributes.each do |attribute| + expect(new_build.send(attribute)).to eq build.send(attribute) + end + end + + it 'does not clone forbidden attributes' do + forbidden_attributes = %w[id status token user artifacts_file + artifacts_metadata coverage] + + forbidden_attributes.each do |attribute| + expect(new_build.send(attribute)).not_to eq build.send(attribute) + end + end + end + describe '#execute' do let(:new_build) { service.execute(build) } @@ -18,6 +46,8 @@ describe Ci::RetryBuildService, :services do project.add_developer(user) end + it_behaves_like 'build duplication' + it 'creates a new build that represents the old one' do expect(new_build.name).to eq build.name end @@ -62,6 +92,8 @@ describe Ci::RetryBuildService, :services do project.add_developer(user) end + it_behaves_like 'build duplication' + it 'creates a new build that represents the old one' do expect(new_build.name).to eq build.name end