From f9c5f18d448de3fefced3149550263adc83af1bf Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 28 Jun 2016 14:24:43 +0200 Subject: [PATCH] Improve method that tells if build is retryable This method now should return false if build is not completed. If build is running then it is not retryable, therefore `Ci::Build#retryable?` returned wrong value. This commit changes this behavior --- app/models/ci/build.rb | 2 +- app/views/projects/builds/_sidebar.html.haml | 2 +- spec/models/build_spec.rb | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 2b0bec33131..c11f8e6884d 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -90,7 +90,7 @@ module Ci end def retryable? - project.builds_enabled? && commands.present? + project.builds_enabled? && commands.present? && complete? end def retried? diff --git a/app/views/projects/builds/_sidebar.html.haml b/app/views/projects/builds/_sidebar.html.haml index a1dc79aaf5e..cab21f0cf19 100644 --- a/app/views/projects/builds/_sidebar.html.haml +++ b/app/views/projects/builds/_sidebar.html.haml @@ -40,7 +40,7 @@ .block{ class: ("block-first" if !@build.coverage && !(can?(current_user, :read_build, @project) && (@build.artifacts? || @build.artifacts_expired?))) } .title Build details - - if @build.retryable? && !@build.active? + - if @build.retryable? = link_to "Retry", retry_namespace_project_build_path(@project.namespace, @project, @build), class: 'pull-right', method: :post - if @build.merge_request %p.build-detail-row diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index 8154001cf46..97b28686d82 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -669,4 +669,22 @@ describe Ci::Build, models: true do expect(build.commit).to eq project.commit end end + + describe '#retryable?' do + context 'when build is running' do + before { build.run! } + + it 'should return false' do + expect(build.retryable?).to be false + end + end + + context 'when build is finished' do + before { build.success! } + + it 'should return true' do + expect(build.retryable?).to be true + end + end + end end