Commit 2cc8f43e authored by Grzegorz Bizon's avatar Grzegorz Bizon

Introduce generic manual action extended status class

parent 53219857
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
......@@ -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
......
......@@ -6,11 +6,7 @@ module Gitlab
include Status::Extended
def label
if has_action?
'manual play action'
else
'manual play action (not allowed)'
end
end
def has_action?
......
......@@ -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
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'
expect(status.label).to eq 'manual stop action (not allowed)'
expect(status).to have_details
expect(status).to have_action
expect(status).not_to have_action
end
end
end
end
......
......@@ -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 '#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
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) }
it { is_expected.to have_action }
end
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
it { is_expected.not_to have_action }
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