summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-05-05 15:13:58 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-05-05 15:13:58 +0200
commit2cc8f43e54d2b653a4f2e80c57339acb11dcba86 (patch)
treedc3dd72419bffebed74207c9a1ba4adfa0ae09f8
parent53219857dd9f97516c6f24f6efb4f405998d9ff2 (diff)
downloadgitlab-ce-2cc8f43e54d2b653a4f2e80c57339acb11dcba86.tar.gz
Introduce generic manual action extended status class
-rw-r--r--lib/gitlab/ci/status/build/action.rb23
-rw-r--r--lib/gitlab/ci/status/build/factory.rb3
-rw-r--r--lib/gitlab/ci/status/build/play.rb6
-rw-r--r--spec/lib/gitlab/ci/status/build/factory_spec.rb32
-rw-r--r--spec/lib/gitlab/ci/status/build/play_spec.rb36
5 files changed, 57 insertions, 43 deletions
diff --git a/lib/gitlab/ci/status/build/action.rb b/lib/gitlab/ci/status/build/action.rb
new file mode 100644
index 00000000000..1397c35145a
--- /dev/null
+++ b/lib/gitlab/ci/status/build/action.rb
@@ -0,0 +1,23 @@
+module Gitlab
+ module Ci
+ module Status
+ module Build
+ class Action < SimpleDelegator
+ include Status::Extended
+
+ def label
+ if has_action?
+ __getobj__.label
+ else
+ "#{__getobj__.label} (not allowed)"
+ end
+ end
+
+ def self.matches?(build, user)
+ build.action?
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/build/factory.rb b/lib/gitlab/ci/status/build/factory.rb
index 38ac6edc9f1..c852d607373 100644
--- a/lib/gitlab/ci/status/build/factory.rb
+++ b/lib/gitlab/ci/status/build/factory.rb
@@ -8,7 +8,8 @@ module Gitlab
Status::Build::Retryable],
[Status::Build::FailedAllowed,
Status::Build::Play,
- Status::Build::Stop]]
+ Status::Build::Stop],
+ [Status::Build::Action]]
end
def self.common_helpers
diff --git a/lib/gitlab/ci/status/build/play.rb b/lib/gitlab/ci/status/build/play.rb
index fae34a2f927..3495b8d0448 100644
--- a/lib/gitlab/ci/status/build/play.rb
+++ b/lib/gitlab/ci/status/build/play.rb
@@ -6,11 +6,7 @@ module Gitlab
include Status::Extended
def label
- if has_action?
- 'manual play action'
- else
- 'manual play action (not allowed)'
- end
+ 'manual play action'
end
def has_action?
diff --git a/spec/lib/gitlab/ci/status/build/factory_spec.rb b/spec/lib/gitlab/ci/status/build/factory_spec.rb
index 2de00c28945..39c5e3658d9 100644
--- a/spec/lib/gitlab/ci/status/build/factory_spec.rb
+++ b/spec/lib/gitlab/ci/status/build/factory_spec.rb
@@ -204,11 +204,12 @@ describe Gitlab::Ci::Status::Build::Factory do
it 'matches correct extended statuses' do
expect(factory.extended_statuses)
- .to eq [Gitlab::Ci::Status::Build::Play]
+ .to eq [Gitlab::Ci::Status::Build::Play,
+ Gitlab::Ci::Status::Build::Action]
end
- it 'fabricates a play detailed status' do
- expect(status).to be_a Gitlab::Ci::Status::Build::Play
+ it 'fabricates action detailed status' do
+ expect(status).to be_a Gitlab::Ci::Status::Build::Action
end
it 'fabricates status with correct details' do
@@ -247,21 +248,24 @@ describe Gitlab::Ci::Status::Build::Factory do
it 'matches correct extended statuses' do
expect(factory.extended_statuses)
- .to eq [Gitlab::Ci::Status::Build::Stop]
+ .to eq [Gitlab::Ci::Status::Build::Stop,
+ Gitlab::Ci::Status::Build::Action]
end
- it 'fabricates a stop detailed status' do
- expect(status).to be_a Gitlab::Ci::Status::Build::Stop
+ it 'fabricates action detailed status' do
+ expect(status).to be_a Gitlab::Ci::Status::Build::Action
end
- it 'fabricates status with correct details' do
- expect(status.text).to eq 'manual'
- expect(status.group).to eq 'manual'
- expect(status.icon).to eq 'icon_status_manual'
- expect(status.favicon).to eq 'favicon_status_manual'
- expect(status.label).to eq 'manual stop action'
- expect(status).to have_details
- expect(status).to have_action
+ context 'when user is not allowed to execute manual action' do
+ it 'fabricates status with correct details' do
+ expect(status.text).to eq 'manual'
+ expect(status.group).to eq 'manual'
+ expect(status.icon).to eq 'icon_status_manual'
+ expect(status.favicon).to eq 'favicon_status_manual'
+ expect(status.label).to eq 'manual stop action (not allowed)'
+ expect(status).to have_details
+ expect(status).not_to have_action
+ end
end
end
end
diff --git a/spec/lib/gitlab/ci/status/build/play_spec.rb b/spec/lib/gitlab/ci/status/build/play_spec.rb
index abefdbe7c66..f5d0f977768 100644
--- a/spec/lib/gitlab/ci/status/build/play_spec.rb
+++ b/spec/lib/gitlab/ci/status/build/play_spec.rb
@@ -7,38 +7,28 @@ describe Gitlab::Ci::Status::Build::Play do
subject { described_class.new(status) }
- context 'when user is allowed to update build' do
- context 'when user can push to branch' do
- before { build.project.add_master(user) }
+ describe '#label' do
+ it 'has a label that says it is a manual action' do
+ expect(subject.label).to eq 'manual play action'
+ end
+ end
+
+ describe '#has_action?' do
+ context 'when user is allowed to update build' do
+ context 'when user can push to branch' do
+ before { build.project.add_master(user) }
- describe '#has_action?' do
it { is_expected.to have_action }
end
- describe '#label' do
- it 'has a label that says it is a manual action' do
- expect(subject.label).to eq 'manual play action'
- end
- end
- end
+ context 'when user can not push to the branch' do
+ before { build.project.add_developer(user) }
- context 'when user can not push to the branch' do
- before { build.project.add_developer(user) }
-
- describe 'has_action?' do
it { is_expected.not_to have_action }
end
-
- describe '#label' do
- it 'has a label that says user is not allowed to play it' do
- expect(subject.label).to eq 'manual play action (not allowed)'
- end
- end
end
- end
- context 'when user is not allowed to update build' do
- describe '#has_action?' do
+ context 'when user is not allowed to update build' do
it { is_expected.not_to have_action }
end
end