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
This commit is contained in:
Grzegorz Bizon 2016-06-28 14:24:43 +02:00
parent 94cec500c5
commit f9c5f18d44
3 changed files with 20 additions and 2 deletions

View file

@ -90,7 +90,7 @@ module Ci
end
def retryable?
project.builds_enabled? && commands.present?
project.builds_enabled? && commands.present? && complete?
end
def retried?

View file

@ -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

View file

@ -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