Commit 068a5395 authored by Matija Čupić's avatar Matija Čupić Committed by Kamil Trzciński

Move #unrecoverable? to CommitStatus model

The #unrecoverable? and #recoverable? methods were in the presenter but
were related to domain logic. This commit moves them to the model to
better reflect their purpose.
parent ee33e657
......@@ -267,8 +267,16 @@ class CommitStatus < ApplicationRecord
end
end
def recoverable?
failed? && !unrecoverable_failure?
end
private
def unrecoverable_failure?
script_failure? || missing_dependency_failure? || archived_failure? || scheduler_failure? || data_integrity_failure?
end
def schedule_stage_and_pipeline_update
if Feature.enabled?(:ci_atomic_processing, project)
# Atomic Processing requires only single Worker
......
......@@ -33,14 +33,6 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated
def callout_failure_message
self.class.callout_failure_messages.fetch(failure_reason.to_sym)
end
def recoverable?
failed? && !unrecoverable?
end
def unrecoverable?
script_failure? || missing_dependency_failure? || archived_failure? || scheduler_failure? || data_integrity_failure?
end
end
CommitStatusPresenter.prepend_if_ee('::EE::CommitStatusPresenter')
......@@ -751,4 +751,48 @@ describe CommitStatus do
it { is_expected.to be_a(CommitStatusPresenter) }
end
describe '#recoverable?' do
using RSpec::Parameterized::TableSyntax
let(:commit_status) { create(:commit_status, :pending) }
subject(:recoverable?) { commit_status.recoverable? }
context 'when commit status is failed' do
before do
commit_status.drop!
end
where(:failure_reason, :recoverable) do
:script_failure | false
:missing_dependency_failure | false
:archived_failure | false
:scheduler_failure | false
:data_integrity_failure | false
:unknown_failure | true
:api_failure | true
:stuck_or_timeout_failure | true
:runner_system_failure | true
end
with_them do
context "when failure reason is #{params[:failure_reason]}" do
before do
commit_status.update_attribute(:failure_reason, failure_reason)
end
it { is_expected.to eq(recoverable) }
end
end
end
context 'when commit status is not failed' do
before do
commit_status.success!
end
it { is_expected.to eq(false) }
end
end
end
......@@ -264,30 +264,4 @@ describe Ci::BuildPresenter do
expect(description).to eq('There has been an API failure, please try again')
end
end
describe '#recoverable?' do
let(:build) { create(:ci_build, :failed, :script_failure) }
context 'when is a script or missing dependency failure' do
let(:failure_reasons) { %w(script_failure missing_dependency_failure archived_failure scheduler_failure data_integrity_failure) }
it 'returns false' do
failure_reasons.each do |failure_reason|
build.update_attribute(:failure_reason, failure_reason)
expect(presenter.recoverable?).to be_falsy
end
end
end
context 'when is any other failure type' do
let(:failure_reasons) { %w(unknown_failure api_failure stuck_or_timeout_failure runner_system_failure) }
it 'returns true' do
failure_reasons.each do |failure_reason|
build.update_attribute(:failure_reason, failure_reason)
expect(presenter.recoverable?).to be_truthy
end
end
end
end
end
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