2017-07-03 17:01:05 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Ci::PipelinePolicy, :models do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
|
|
|
|
|
2017-07-03 17:20:44 -04:00
|
|
|
let(:policy) do
|
|
|
|
described_class.new(user, pipeline)
|
2017-07-03 17:01:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'rules' do
|
|
|
|
describe 'rules for protected branch' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
create(:protected_branch, branch_policy,
|
|
|
|
name: pipeline.ref, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no one can push or merge to the branch' do
|
|
|
|
let(:branch_policy) { :no_one_can_push }
|
|
|
|
|
|
|
|
it 'does not include ability to update pipeline' do
|
2017-07-03 17:20:44 -04:00
|
|
|
expect(policy).to be_disallowed :update_pipeline
|
2017-07-03 17:01:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when developers can push to the branch' do
|
|
|
|
let(:branch_policy) { :developers_can_push }
|
|
|
|
|
|
|
|
it 'includes ability to update pipeline' do
|
2017-07-03 17:20:44 -04:00
|
|
|
expect(policy).to be_allowed :update_pipeline
|
2017-07-03 17:01:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when developers can push to the branch' do
|
|
|
|
let(:branch_policy) { :developers_can_merge }
|
|
|
|
|
|
|
|
it 'includes ability to update pipeline' do
|
2017-07-03 17:20:44 -04:00
|
|
|
expect(policy).to be_allowed :update_pipeline
|
2017-07-03 17:01:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|