summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-04-06 03:10:52 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-04-06 03:10:52 +0800
commite258e6f1471fb176e39daf6fef7785af120c2178 (patch)
tree374873e6eebb747c4d19ec065f2f2fa49a86d0cb
parent6bf1780aa81a45afdf9ddbfc32c2b9f1e0ba9285 (diff)
downloadgitlab-ce-e258e6f1471fb176e39daf6fef7785af120c2178.tar.gz
Add test for presenters
-rw-r--r--app/models/ci/pipeline.rb4
-rw-r--r--app/presenters/ci/pipeline_presenter.rb4
-rw-r--r--spec/presenters/ci/build_presenter_spec.rb32
-rw-r--r--spec/presenters/ci/pipeline_presenter_spec.rb54
4 files changed, 90 insertions, 4 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 9ef35ebdd50..8aad149519e 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -219,6 +219,10 @@ module Ci
statuses.cancelable.any?
end
+ def auto_canceled?
+ canceled? && auto_canceled_by_id?
+ end
+
def cancel_running
Gitlab::OptimisticLocking.retry_lock(
statuses.cancelable) do |cancelable|
diff --git a/app/presenters/ci/pipeline_presenter.rb b/app/presenters/ci/pipeline_presenter.rb
index 8f9e4fa707d..b8e74bf5509 100644
--- a/app/presenters/ci/pipeline_presenter.rb
+++ b/app/presenters/ci/pipeline_presenter.rb
@@ -2,10 +2,6 @@ module Ci
class PipelinePresenter < Gitlab::View::Presenter::Delegated
presents :pipeline
- def auto_canceled?
- canceled? && auto_canceled_by_id?
- end
-
def status_title
"Pipeline is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" if auto_canceled?
end
diff --git a/spec/presenters/ci/build_presenter_spec.rb b/spec/presenters/ci/build_presenter_spec.rb
index 7a35da38b2b..a9a8df1550d 100644
--- a/spec/presenters/ci/build_presenter_spec.rb
+++ b/spec/presenters/ci/build_presenter_spec.rb
@@ -57,6 +57,38 @@ describe Ci::BuildPresenter do
end
end
+ describe '#status_title' do
+ context 'when build is canceled' do
+ before do
+ expect(presenter).to receive(:canceled?).and_return(true)
+ end
+
+ context 'when pipeline is auto-canceled' do
+ before do
+ expect(pipeline).to receive(:auto_canceled?).and_return(true)
+ expect(pipeline).to receive(:auto_canceled_by_id).and_return(1)
+ end
+
+ it 'shows that the job is auto-canceled' do
+ status_title = presenter.status_title
+
+ expect(status_title).to include('auto-canceled')
+ expect(status_title).to include('Pipeline #1')
+ end
+ end
+
+ context 'when pipeline is not auto-canceled' do
+ before do
+ expect(pipeline).to receive(:auto_canceled?).and_return(false)
+ end
+
+ it 'shows that the job is auto-canceled' do
+ expect(presenter.status_title).to be_nil
+ end
+ end
+ end
+ end
+
describe 'quack like a Ci::Build permission-wise' do
context 'user is not allowed' do
let(:project) { build_stubbed(:empty_project, public_builds: false) }
diff --git a/spec/presenters/ci/pipeline_presenter_spec.rb b/spec/presenters/ci/pipeline_presenter_spec.rb
new file mode 100644
index 00000000000..449e45c1f4c
--- /dev/null
+++ b/spec/presenters/ci/pipeline_presenter_spec.rb
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+describe Ci::PipelinePresenter do
+ let(:project) { create(:empty_project) }
+ let(:pipeline) { create(:ci_pipeline, project: project) }
+
+ subject(:presenter) do
+ described_class.new(pipeline)
+ end
+
+ it 'inherits from Gitlab::View::Presenter::Delegated' do
+ expect(described_class.superclass).to eq(Gitlab::View::Presenter::Delegated)
+ end
+
+ describe '#initialize' do
+ it 'takes a pipeline and optional params' do
+ expect { presenter }.not_to raise_error
+ end
+
+ it 'exposes pipeline' do
+ expect(presenter.pipeline).to eq(pipeline)
+ end
+
+ it 'forwards missing methods to pipeline' do
+ expect(presenter.ref).to eq(pipeline.ref)
+ end
+ end
+
+ describe '#status_title' do
+ context 'when pipeline is auto-canceled' do
+ before do
+ expect(pipeline).to receive(:auto_canceled?).and_return(true)
+ expect(pipeline).to receive(:auto_canceled_by_id).and_return(1)
+ end
+
+ it 'shows that the pipeline is auto-canceled' do
+ status_title = presenter.status_title
+
+ expect(status_title).to include('auto-canceled')
+ expect(status_title).to include('Pipeline #1')
+ end
+ end
+
+ context 'when pipeline is not auto-canceled' do
+ before do
+ expect(pipeline).to receive(:auto_canceled?).and_return(false)
+ end
+
+ it 'shows that the job is auto-canceled' do
+ expect(presenter.status_title).to be_nil
+ end
+ end
+ end
+end