Commit d9b78477 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '46177-fix-present-on-generic-commit-status' into 'master'

Resolve "NoMethodError: undefined method `present' for #<GenericCommitStatus:0x00007f6eacf34a40>"

Closes #46177

See merge request gitlab-org/gitlab-ce!18979
parents 2eb8099f 22d3e90c
...@@ -2,6 +2,7 @@ class CommitStatus < ActiveRecord::Base ...@@ -2,6 +2,7 @@ class CommitStatus < ActiveRecord::Base
include HasStatus include HasStatus
include Importable include Importable
include AfterCommitQueue include AfterCommitQueue
include Presentable
self.table_name = 'ci_builds' self.table_name = 'ci_builds'
......
module Ci module Ci
class BuildPresenter < Gitlab::View::Presenter::Delegated class BuildPresenter < CommitStatusPresenter
CALLOUT_FAILURE_MESSAGES = {
unknown_failure: 'There is an unknown failure, please try again',
script_failure: 'There has been a script failure. Check the job log for more information',
api_failure: 'There has been an API failure, please try again',
stuck_or_timeout_failure: 'There has been a timeout failure or the job got stuck. Check your timeout limits or try again',
runner_system_failure: 'There has been a runner system failure, please try again',
missing_dependency_failure: 'There has been a missing dependency failure, check the job log for more information'
}.freeze
presents :build
def erased_by_user? def erased_by_user?
# Build can be erased through API, therefore it does not have # Build can be erased through API, therefore it does not have
# `erased_by` user assigned in that case. # `erased_by` user assigned in that case.
...@@ -44,14 +33,6 @@ module Ci ...@@ -44,14 +33,6 @@ module Ci
"#{subject.name} - #{detailed_status.status_tooltip}" "#{subject.name} - #{detailed_status.status_tooltip}"
end end
def callout_failure_message
CALLOUT_FAILURE_MESSAGES[failure_reason.to_sym]
end
def recoverable?
failed? && !unrecoverable?
end
private private
def tooltip_for_badge def tooltip_for_badge
...@@ -61,9 +42,5 @@ module Ci ...@@ -61,9 +42,5 @@ module Ci
def detailed_status def detailed_status
@detailed_status ||= subject.detailed_status(user) @detailed_status ||= subject.detailed_status(user)
end end
def unrecoverable?
script_failure? || missing_dependency_failure?
end
end end
end end
class CommitStatusPresenter < Gitlab::View::Presenter::Delegated
CALLOUT_FAILURE_MESSAGES = {
unknown_failure: 'There is an unknown failure, please try again',
script_failure: 'There has been a script failure. Check the job log for more information',
api_failure: 'There has been an API failure, please try again',
stuck_or_timeout_failure: 'There has been a timeout failure or the job got stuck. Check your timeout limits or try again',
runner_system_failure: 'There has been a runner system failure, please try again',
missing_dependency_failure: 'There has been a missing dependency failure, check the job log for more information'
}.freeze
presents :build
def callout_failure_message
CALLOUT_FAILURE_MESSAGES[failure_reason.to_sym]
end
def recoverable?
failed? && !unrecoverable?
end
def unrecoverable?
script_failure? || missing_dependency_failure?
end
end
class GenericCommitStatusPresenter < CommitStatusPresenter
end
---
title: Allow CommitStatus class to use presentable methods
merge_request: 18979
author:
type: fixed
...@@ -565,4 +565,10 @@ describe CommitStatus do ...@@ -565,4 +565,10 @@ describe CommitStatus do
it_behaves_like 'commit status enqueued' it_behaves_like 'commit status enqueued'
end end
end end
describe '#present' do
subject { commit_status.present }
it { is_expected.to be_a(CommitStatusPresenter) }
end
end end
...@@ -78,4 +78,10 @@ describe GenericCommitStatus do ...@@ -78,4 +78,10 @@ describe GenericCommitStatus do
it { is_expected.not_to be_nil } it { is_expected.not_to be_nil }
end end
end end
describe '#present' do
subject { generic_commit_status.present }
it { is_expected.to be_a(GenericCommitStatusPresenter) }
end
end end
...@@ -10,7 +10,7 @@ describe Ci::BuildPresenter do ...@@ -10,7 +10,7 @@ describe Ci::BuildPresenter do
end end
it 'inherits from Gitlab::View::Presenter::Delegated' do it 'inherits from Gitlab::View::Presenter::Delegated' do
expect(described_class.superclass).to eq(Gitlab::View::Presenter::Delegated) expect(described_class.ancestors).to include(Gitlab::View::Presenter::Delegated)
end end
describe '#initialize' do describe '#initialize' do
......
require 'spec_helper'
describe CommitStatusPresenter do
let(:project) { create(:project) }
let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, pipeline: pipeline) }
subject(:presenter) do
described_class.new(build)
end
it 'inherits from Gitlab::View::Presenter::Delegated' do
expect(described_class.superclass).to eq(Gitlab::View::Presenter::Delegated)
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