Commit a27cf281 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Unify build policy tests and pipeline policy tests

parent 679789ee
...@@ -96,7 +96,7 @@ describe Ci::BuildPolicy, :models do ...@@ -96,7 +96,7 @@ describe Ci::BuildPolicy, :models do
end end
end end
describe 'rules for protected branch' do describe 'rules for protected ref' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:build) { create(:ci_build, ref: 'some-ref', pipeline: pipeline) } let(:build) { create(:ci_build, ref: 'some-ref', pipeline: pipeline) }
...@@ -107,7 +107,7 @@ describe Ci::BuildPolicy, :models do ...@@ -107,7 +107,7 @@ describe Ci::BuildPolicy, :models do
context 'when no one can push or merge to the branch' do context 'when no one can push or merge to the branch' do
before do before do
create(:protected_branch, :no_one_can_push, create(:protected_branch, :no_one_can_push,
name: 'some-ref', project: project) name: build.ref, project: project)
end end
it 'does not include ability to update build' do it 'does not include ability to update build' do
...@@ -118,7 +118,7 @@ describe Ci::BuildPolicy, :models do ...@@ -118,7 +118,7 @@ describe Ci::BuildPolicy, :models do
context 'when developers can push to the branch' do context 'when developers can push to the branch' do
before do before do
create(:protected_branch, :developers_can_merge, create(:protected_branch, :developers_can_merge,
name: 'some-ref', project: project) name: build.ref, project: project)
end end
it 'includes ability to update build' do it 'includes ability to update build' do
...@@ -129,7 +129,7 @@ describe Ci::BuildPolicy, :models do ...@@ -129,7 +129,7 @@ describe Ci::BuildPolicy, :models do
context 'when no one can create the tag' do context 'when no one can create the tag' do
before do before do
create(:protected_tag, :no_one_can_create, create(:protected_tag, :no_one_can_create,
name: 'some-ref', project: project) name: build.ref, project: project)
build.update(tag: true) build.update(tag: true)
end end
...@@ -142,7 +142,7 @@ describe Ci::BuildPolicy, :models do ...@@ -142,7 +142,7 @@ describe Ci::BuildPolicy, :models do
context 'when no one can create the tag but it is not a tag' do context 'when no one can create the tag but it is not a tag' do
before do before do
create(:protected_tag, :no_one_can_create, create(:protected_tag, :no_one_can_create,
name: 'some-ref', project: project) name: build.ref, project: project)
end end
it 'includes ability to update build' do it 'includes ability to update build' do
......
...@@ -9,18 +9,18 @@ describe Ci::PipelinePolicy, :models do ...@@ -9,18 +9,18 @@ describe Ci::PipelinePolicy, :models do
end end
describe 'rules' do describe 'rules' do
describe 'rules for protected branch' do describe 'rules for protected ref' do
let(:project) { create(:project) } let(:project) { create(:project) }
before do before do
project.add_developer(user) project.add_developer(user)
create(:protected_branch, branch_policy,
name: pipeline.ref, project: project)
end end
context 'when no one can push or merge to the branch' do context 'when no one can push or merge to the branch' do
let(:branch_policy) { :no_one_can_push } before do
create(:protected_branch, :no_one_can_push,
name: pipeline.ref, project: project)
end
it 'does not include ability to update pipeline' do it 'does not include ability to update pipeline' do
expect(policy).to be_disallowed :update_pipeline expect(policy).to be_disallowed :update_pipeline
...@@ -28,15 +28,34 @@ describe Ci::PipelinePolicy, :models do ...@@ -28,15 +28,34 @@ describe Ci::PipelinePolicy, :models do
end end
context 'when developers can push to the branch' do context 'when developers can push to the branch' do
let(:branch_policy) { :developers_can_push } before do
create(:protected_branch, :developers_can_merge,
name: pipeline.ref, project: project)
end
it 'includes ability to update pipeline' do it 'includes ability to update pipeline' do
expect(policy).to be_allowed :update_pipeline expect(policy).to be_allowed :update_pipeline
end end
end end
context 'when developers can push to the branch' do context 'when no one can create the tag' do
let(:branch_policy) { :developers_can_merge } before do
create(:protected_tag, :no_one_can_create,
name: pipeline.ref, project: project)
pipeline.update(tag: true)
end
it 'does not include ability to update pipeline' do
expect(policy).to be_disallowed :update_pipeline
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.ref, project: project)
end
it 'includes ability to update pipeline' do it 'includes ability to update pipeline' do
expect(policy).to be_allowed :update_pipeline expect(policy).to be_allowed :update_pipeline
......
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