2019-10-24 20:06:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-08 02:49:55 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe Ci::PipelineSchedulePolicy, :models do
|
2020-02-18 10:08:51 -05:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:pipeline_schedule, reload: true) { create(:ci_pipeline_schedule, :nightly, project: project) }
|
2017-12-08 02:49:55 -05:00
|
|
|
|
|
|
|
let(:policy) do
|
|
|
|
described_class.new(user, pipeline_schedule)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'rules' do
|
|
|
|
describe 'rules for protected ref' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no one can push or merge to the branch' do
|
|
|
|
before do
|
|
|
|
create(:protected_branch, :no_one_can_push,
|
|
|
|
name: pipeline_schedule.ref, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include ability to play pipeline schedule' do
|
|
|
|
expect(policy).to be_disallowed :play_pipeline_schedule
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when developers can push to the branch' do
|
|
|
|
before do
|
|
|
|
create(:protected_branch, :developers_can_merge,
|
|
|
|
name: pipeline_schedule.ref, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes ability to update pipeline' do
|
|
|
|
expect(policy).to be_allowed :play_pipeline_schedule
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no one can create the tag' do
|
|
|
|
let(:tag) { 'v1.0.0' }
|
|
|
|
|
|
|
|
before do
|
2020-07-29 08:09:45 -04:00
|
|
|
pipeline_schedule.update!(ref: tag)
|
2017-12-08 02:49:55 -05:00
|
|
|
|
|
|
|
create(:protected_tag, :no_one_can_create,
|
|
|
|
name: pipeline_schedule.ref, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include ability to play pipeline schedule' do
|
|
|
|
expect(policy).to be_disallowed :play_pipeline_schedule
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no one can create the tag but it is not a tag' do
|
|
|
|
before do
|
|
|
|
create(:protected_tag, :no_one_can_create,
|
|
|
|
name: pipeline_schedule.ref, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes ability to play pipeline schedule' do
|
|
|
|
expect(policy).to be_allowed :play_pipeline_schedule
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'rules for owner of schedule' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
2020-07-29 08:09:45 -04:00
|
|
|
pipeline_schedule.update!(owner: user)
|
2017-12-08 02:49:55 -05:00
|
|
|
end
|
|
|
|
|
2018-11-19 09:08:23 -05:00
|
|
|
it 'includes abilities to do all operations on pipeline schedule' do
|
2017-12-08 02:49:55 -05:00
|
|
|
expect(policy).to be_allowed :play_pipeline_schedule
|
|
|
|
expect(policy).to be_allowed :update_pipeline_schedule
|
|
|
|
expect(policy).to be_allowed :admin_pipeline_schedule
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
describe 'rules for a maintainer' do
|
2017-12-08 02:49:55 -05:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-12-08 02:49:55 -05:00
|
|
|
end
|
|
|
|
|
2022-05-02 20:08:25 -04:00
|
|
|
it 'allows for playing and destroying a pipeline schedule' do
|
2017-12-08 02:49:55 -05:00
|
|
|
expect(policy).to be_allowed :play_pipeline_schedule
|
|
|
|
expect(policy).to be_allowed :admin_pipeline_schedule
|
|
|
|
end
|
2022-05-02 20:08:25 -04:00
|
|
|
|
|
|
|
it 'does not allow for updating of an existing schedule' do
|
|
|
|
expect(policy).not_to be_allowed :update_pipeline_schedule
|
|
|
|
end
|
2017-12-08 02:49:55 -05:00
|
|
|
end
|
2017-07-20 06:54:36 -04:00
|
|
|
|
|
|
|
describe 'rules for non-owner of schedule' do
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(owner)
|
|
|
|
project.add_maintainer(user)
|
2020-07-29 08:09:45 -04:00
|
|
|
pipeline_schedule.update!(owner: owner)
|
2017-07-20 06:54:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes abilities to take ownership' do
|
|
|
|
expect(policy).to be_allowed :take_ownership_pipeline_schedule
|
|
|
|
end
|
|
|
|
end
|
2017-12-08 02:49:55 -05:00
|
|
|
end
|
|
|
|
end
|