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 | |
parent | cb5e35d562a1bf0737c1ad3316c3723775fada01 (diff) | |
download | gitlab-ce-afef38533727cf32a7be324243a25b4db5eb5498.tar.gz |
Add doc. Fix spec. Add erase_build in protected_ref rule
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/jobs_controller_spec.rb | 25 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 4 | ||||
-rw-r--r-- | spec/policies/ci/build_policy_spec.rb | 40 | ||||
-rw-r--r-- | spec/requests/api/jobs_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/v3/builds_spec.rb | 2 |
5 files changed, 59 insertions, 14 deletions
diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb index f9688949a19..804075782c1 100644 --- a/spec/controllers/projects/jobs_controller_spec.rb +++ b/spec/controllers/projects/jobs_controller_spec.rb @@ -372,12 +372,14 @@ describe Projects::JobsController do describe 'POST erase' do before do - project.add_developer(user) + project.team << [user, role] sign_in(user) post_erase end + let(:role) { :master } + context 'when job is erasable' do let(:job) { create(:ci_build, :erasable, :trace, pipeline: pipeline) } @@ -404,6 +406,27 @@ describe Projects::JobsController do end end + context 'when user is developer' do + let(:role) { :developer } + let(:job) { create(:ci_build, :erasable, :trace, pipeline: pipeline, user: triggered_by) } + + context 'when triggered by same user' do + let(:triggered_by) { user } + + it 'has successful status' do + expect(response).to have_gitlab_http_status(:found) + end + end + + context 'when triggered by different user' do + let(:triggered_by) { create(:user) } + + it 'does not have successful status' do + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + def post_erase post :erase, namespace_id: project.namespace, project_id: project, diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 88f7b1775a0..1795ee8e9a4 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -270,8 +270,8 @@ describe Ci::Build do end end - describe '#owned_by?' do - subject { build.owned_by?(user) } + describe '#triggered_by?' do + subject { build.triggered_by?(user) } context 'when user is owner' do let(:build) { create(:ci_build, pipeline: pipeline, user: user) } 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 } diff --git a/spec/requests/api/jobs_spec.rb b/spec/requests/api/jobs_spec.rb index 3b7b9c889e7..8196046f6ab 100644 --- a/spec/requests/api/jobs_spec.rb +++ b/spec/requests/api/jobs_spec.rb @@ -491,6 +491,8 @@ describe API::Jobs do describe 'POST /projects/:id/jobs/:job_id/erase' do before do + project.add_master(user) + post api("/projects/#{project.id}/jobs/#{job.id}/erase", user) end diff --git a/spec/requests/api/v3/builds_spec.rb b/spec/requests/api/v3/builds_spec.rb index 3f58b7ef384..a73bb456b52 100644 --- a/spec/requests/api/v3/builds_spec.rb +++ b/spec/requests/api/v3/builds_spec.rb @@ -408,6 +408,8 @@ describe API::V3::Builds do describe 'POST /projects/:id/builds/:build_id/erase' do before do + project.add_master(user) + post v3_api("/projects/#{project.id}/builds/#{build.id}/erase", user) end |