diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-11-07 02:47:05 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-11-07 02:47:05 +0900 |
commit | afef38533727cf32a7be324243a25b4db5eb5498 (patch) | |
tree | cfdd2c96bd0c1a7ee1fd85f0b63fd2edf0d1fe3f /spec/policies | |
parent | cb5e35d562a1bf0737c1ad3316c3723775fada01 (diff) | |
download | gitlab-ce-afef38533727cf32a7be324243a25b4db5eb5498.tar.gz |
Add doc. Fix spec. Add erase_build in protected_ref rule
Diffstat (limited to 'spec/policies')
-rw-r--r-- | spec/policies/ci/build_policy_spec.rb | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/spec/policies/ci/build_policy_spec.rb b/spec/policies/ci/build_policy_spec.rb index d8e73e4a890..edf8d63a4c6 100644 --- a/spec/policies/ci/build_policy_spec.rb +++ b/spec/policies/ci/build_policy_spec.rb @@ -152,39 +152,57 @@ describe Ci::BuildPolicy do end describe 'rules for erase build' do - let(:project) { create(:project, :repository) } - let(:build) { create(:ci_build, pipeline: pipeline, user: owner) } + let(:project) { create(:project) } + let(:build) { create(:ci_build, pipeline: pipeline, ref: 'some-ref', user: owner) } - context 'when developer created a build' do + context 'when a developer erases a build' do before do project.add_developer(user) end - context 'when the build was created by the user' do - let(:owner) { user } + context 'when developers can push to the branch' do + before do + create(:protected_branch, :developers_can_merge, + name: build.ref, project: project) + end - it { expect(policy).to be_allowed :erase_build } + context 'when the build was created by the developer' do + let(:owner) { user } + + it { expect(policy).to be_allowed :erase_build } + end + + context 'when the build was created by the other' do + let(:owner) { create(:user) } + + it { expect(policy).to be_disallowed :erase_build } + end end - context 'when the build was created by others' do - let(:owner) { create(:user) } + context 'when no one can push or merge to the branch' do + let(:owner) { user } + + before do + create(:protected_branch, :no_one_can_push, + name: build.ref, project: project) + end it { expect(policy).to be_disallowed :erase_build } end end - context 'when master erases a build' do + context 'when a master erases a build' do before do project.add_master(user) end - context 'when the build was created by the user' do + context 'when the build was created by the master' do let(:owner) { user } it { expect(policy).to be_allowed :erase_build } end - context 'when the build was created by others' do + context 'when the build was created by the other' do let(:owner) { create(:user) } it { expect(policy).to be_allowed :erase_build } |