diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-02-16 15:13:10 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-02-16 15:13:10 +0300 |
commit | 953e590b18289005c69b72575ae6f38161ffa11b (patch) | |
tree | d47e5a38ae58163d055f6692112d6a1ac6b073c5 /spec | |
parent | 658c5f32a3eac2f4a478e84ad767ba000041b461 (diff) |
Make build clone/retry implementation more robust
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/ci/builds.rb | 13 | ||||
-rw-r--r-- | spec/services/ci/retry_build_service_spec.rb | 36 |
2 files changed, 32 insertions, 17 deletions
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 0397d5d4001..4f671091afc 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -89,8 +89,9 @@ FactoryGirl.define do tag true end - factory :ci_build_with_coverage do + trait :coverage do coverage 99.9 + coverage_regex '/(d+)/' end trait :trace do @@ -99,6 +100,16 @@ FactoryGirl.define do end end + trait :erased do + erased_at Time.now + erased_by factory: :user + end + + trait :queued do + queued_at Time.now + runner factory: :ci_runner + end + trait :artifacts do after(:create) do |build, _| build.artifacts_file = diff --git a/spec/services/ci/retry_build_service_spec.rb b/spec/services/ci/retry_build_service_spec.rb index d3cc9fea4df..93147870afe 100644 --- a/spec/services/ci/retry_build_service_spec.rb +++ b/spec/services/ci/retry_build_service_spec.rb @@ -12,29 +12,33 @@ describe Ci::RetryBuildService, :services do shared_examples 'build duplication' do let(:build) do - create(:ci_build, :failed, :artifacts, - pipeline: pipeline, - coverage: 90.0, - coverage_regex: '/(d+)/') + create(:ci_build, :failed, :artifacts, :erased, :trace, + :queued, :coverage, pipeline: pipeline) 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] + describe 'clone attributes' do + described_class::CLONE_ATTRIBUTES.each do |attribute| + it "clones #{attribute} build attribute" do + expect(new_build.send(attribute)).to eq build.send(attribute) + end + end + end - clone_attributes.each do |attribute| - expect(new_build.send(attribute)).to eq build.send(attribute) + describe 'reject attributes' do + described_class::REJECT_ATTRIBUTES.each do |attribute| + it "does not clone #{attribute} build attribute" do + expect(new_build.send(attribute)).not_to eq build.send(attribute) + end end end - it 'does not clone forbidden attributes' do - forbidden_attributes = %w[id status token user artifacts_file - artifacts_metadata coverage] + it 'has correct number of known attributes' do + attributes = + described_class::CLONE_ATTRIBUTES + + described_class::IGNORE_ATTRIBUTES + + described_class::REJECT_ATTRIBUTES - forbidden_attributes.each do |attribute| - expect(new_build.send(attribute)).not_to eq build.send(attribute) - end + expect(attributes.size).to eq build.attributes.size end end |