Add Presentable concern
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
e5a29b4514
commit
78874519db
|
@ -94,7 +94,7 @@ class Projects::BuildsController < Projects::ApplicationController
|
|||
private
|
||||
|
||||
def build
|
||||
@build ||= project.builds.find_by!(id: params[:id])
|
||||
@build ||= project.builds.find_by!(id: params[:id]).present(current_user)
|
||||
end
|
||||
|
||||
def build_path(build)
|
||||
|
|
|
@ -2,6 +2,7 @@ module Ci
|
|||
class Build < CommitStatus
|
||||
include TokenAuthenticatable
|
||||
include AfterCommitQueue
|
||||
include Presentable
|
||||
|
||||
belongs_to :runner
|
||||
belongs_to :trigger_request
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
module Presentable
|
||||
def present(**attributes)
|
||||
Gitlab::View::Presenter::Factory
|
||||
.new(self, attributes)
|
||||
.fabricate!
|
||||
end
|
||||
end
|
|
@ -51,8 +51,10 @@
|
|||
.prepend-top-default
|
||||
- if @build.erased?
|
||||
.erased.alert.alert-warning
|
||||
- erased_by = "by #{link_to @build.erased_by.name, user_path(@build.erased_by)}" if @build.erased_by
|
||||
Build has been erased #{erased_by.html_safe} #{time_ago_with_tooltip(@build.erased_at)}
|
||||
- if @build.erased_by_user?
|
||||
Build has been erased by #{link_to(@build.erased_by_name, user_path(@build.erased_by))} #{time_ago_with_tooltip(@build.erased_at)}
|
||||
- else
|
||||
Build has been erased #{time_ago_with_tooltip(@build.erased_at)}
|
||||
- else
|
||||
#js-build-scroll.scroll-controls
|
||||
.scroll-step
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Presentable do
|
||||
let(:build) { create(:ci_build) }
|
||||
|
||||
describe '#present' do
|
||||
it 'returns a presenter' do
|
||||
expect(build.present).to be_a(Ci::Build::Presenter)
|
||||
end
|
||||
|
||||
it 'takes optional attributes' do
|
||||
expect(build.present(foo: 'bar').foo).to eq('bar')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue