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 ...@@ -8,7 +8,8 @@ module Gitlab
Status::Build::Retryable], Status::Build::Retryable],
[Status::Build::FailedAllowed, [Status::Build::FailedAllowed,
Status::Build::Play, Status::Build::Play,
Status::Build::Stop]] Status::Build::Stop],
[Status::Build::Action]]
end end
def self.common_helpers def self.common_helpers
......
...@@ -6,11 +6,7 @@ module Gitlab ...@@ -6,11 +6,7 @@ module Gitlab
include Status::Extended include Status::Extended
def label def label
if has_action? 'manual play action'
'manual play action'
else
'manual play action (not allowed)'
end
end end
def has_action? def has_action?
......
...@@ -204,11 +204,12 @@ describe Gitlab::Ci::Status::Build::Factory do ...@@ -204,11 +204,12 @@ describe Gitlab::Ci::Status::Build::Factory do
it 'matches correct extended statuses' do it 'matches correct extended statuses' do
expect(factory.extended_statuses) expect(factory.extended_statuses)
.to eq [Gitlab::Ci::Status::Build::Play] .to eq [Gitlab::Ci::Status::Build::Play,
Gitlab::Ci::Status::Build::Action]
end end
it 'fabricates a play detailed status' do it 'fabricates action detailed status' do
expect(status).to be_a Gitlab::Ci::Status::Build::Play expect(status).to be_a Gitlab::Ci::Status::Build::Action
end end
it 'fabricates status with correct details' do it 'fabricates status with correct details' do
...@@ -247,21 +248,24 @@ describe Gitlab::Ci::Status::Build::Factory do ...@@ -247,21 +248,24 @@ describe Gitlab::Ci::Status::Build::Factory do
it 'matches correct extended statuses' do it 'matches correct extended statuses' do
expect(factory.extended_statuses) expect(factory.extended_statuses)
.to eq [Gitlab::Ci::Status::Build::Stop] .to eq [Gitlab::Ci::Status::Build::Stop,
Gitlab::Ci::Status::Build::Action]
end end
it 'fabricates a stop detailed status' do it 'fabricates action detailed status' do
expect(status).to be_a Gitlab::Ci::Status::Build::Stop expect(status).to be_a Gitlab::Ci::Status::Build::Action
end end
it 'fabricates status with correct details' do context 'when user is not allowed to execute manual action' do
expect(status.text).to eq 'manual' it 'fabricates status with correct details' do
expect(status.group).to eq 'manual' expect(status.text).to eq 'manual'
expect(status.icon).to eq 'icon_status_manual' expect(status.group).to eq 'manual'
expect(status.favicon).to eq 'favicon_status_manual' expect(status.icon).to eq 'icon_status_manual'
expect(status.label).to eq 'manual stop action' expect(status.favicon).to eq 'favicon_status_manual'
expect(status).to have_details expect(status.label).to eq 'manual stop action (not allowed)'
expect(status).to have_action expect(status).to have_details
expect(status).not_to have_action
end
end end
end end
end end
......
...@@ -7,38 +7,28 @@ describe Gitlab::Ci::Status::Build::Play do ...@@ -7,38 +7,28 @@ describe Gitlab::Ci::Status::Build::Play do
subject { described_class.new(status) } subject { described_class.new(status) }
context 'when user is allowed to update build' do describe '#label' do
context 'when user can push to branch' do it 'has a label that says it is a manual action' do
before { build.project.add_master(user) } 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 } it { is_expected.to have_action }
end end
describe '#label' do context 'when user can not push to the branch' do
it 'has a label that says it is a manual action' do before { build.project.add_developer(user) }
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) }
describe 'has_action?' do
it { is_expected.not_to have_action } it { is_expected.not_to have_action }
end 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
end
context 'when user is not allowed to update build' do context 'when user is not allowed to update build' do
describe '#has_action?' do
it { is_expected.not_to have_action } it { is_expected.not_to have_action }
end end
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