diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-11-07 16:45:55 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-11-07 16:45:55 +0300 |
commit | d8fb903ef7db26566cfacf76ce10e9e7917b8f38 (patch) | |
tree | e5cb79ea279bf4aba78f00ea9e21cb7597fecb84 /spec | |
parent | d89c18901bde510da2668e676b3bf2f1e21deef2 (diff) |
Improve spec
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/jobs_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/policies/ci/build_policy_spec.rb | 36 | ||||
-rw-r--r-- | spec/requests/api/jobs_spec.rb | 62 |
3 files changed, 71 insertions, 29 deletions
diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb index 804075782c1..e50962df553 100644 --- a/spec/controllers/projects/jobs_controller_spec.rb +++ b/spec/controllers/projects/jobs_controller_spec.rb @@ -422,7 +422,7 @@ describe Projects::JobsController do let(:triggered_by) { create(:user) } it 'does not have successful status' do - expect(response).to have_gitlab_http_status(:not_found) + expect(response).not_to have_gitlab_http_status(:found) end end end diff --git a/spec/policies/ci/build_policy_spec.rb b/spec/policies/ci/build_policy_spec.rb index edf8d63a4c6..298a9d16425 100644 --- a/spec/policies/ci/build_policy_spec.rb +++ b/spec/policies/ci/build_policy_spec.rb @@ -152,7 +152,7 @@ describe Ci::BuildPolicy do end describe 'rules for erase build' do - let(:project) { create(:project) } + let(:project) { create(:project, :repository) } let(:build) { create(:ci_build, pipeline: pipeline, ref: 'some-ref', user: owner) } context 'when a developer erases a build' do @@ -162,7 +162,7 @@ describe Ci::BuildPolicy do context 'when developers can push to the branch' do before do - create(:protected_branch, :developers_can_merge, + create(:protected_branch, :developers_can_push, name: build.ref, project: project) end @@ -183,7 +183,7 @@ describe Ci::BuildPolicy do let(:owner) { user } before do - create(:protected_branch, :no_one_can_push, + create(:protected_branch, :no_one_can_push, :no_one_can_merge, name: build.ref, project: project) end @@ -196,16 +196,34 @@ describe Ci::BuildPolicy do project.add_master(user) end - context 'when the build was created by the master' do - let(:owner) { user } + context 'when masters can push to the branch' do + before do + create(:protected_branch, :masters_can_push, + name: build.ref, project: project) + end + + 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 the other' do + let(:owner) { create(:user) } - it { expect(policy).to be_allowed :erase_build } + it { expect(policy).to be_allowed :erase_build } + end end - context 'when the build was created by the other' do - let(:owner) { create(:user) } + context 'when no one can push or merge to the branch' do + let(:owner) { user } - it { expect(policy).to be_allowed :erase_build } + before do + create(:protected_branch, :no_one_can_push, :no_one_can_merge, + name: build.ref, project: project) + end + + it { expect(policy).to be_disallowed :erase_build } end end end diff --git a/spec/requests/api/jobs_spec.rb b/spec/requests/api/jobs_spec.rb index 3e0682055fe..327b1176088 100644 --- a/spec/requests/api/jobs_spec.rb +++ b/spec/requests/api/jobs_spec.rb @@ -500,35 +500,59 @@ describe API::Jobs do end describe 'POST /projects/:id/jobs/:job_id/erase' do - before do - project.add_master(user) + context 'when a master erases a build' do + before do + project.add_master(user) - post api("/projects/#{project.id}/jobs/#{job.id}/erase", user) - end + post api("/projects/#{project.id}/jobs/#{job.id}/erase", user) + end + + context 'job is erasable' do + let(:job) { create(:ci_build, :trace, :artifacts, :success, project: project, pipeline: pipeline) } - context 'job is erasable' do - let(:job) { create(:ci_build, :trace, :artifacts, :success, project: project, pipeline: pipeline) } + it 'erases job content' do + expect(response).to have_gitlab_http_status(201) + expect(job).not_to have_trace + expect(job.artifacts_file.exists?).to be_falsy + expect(job.artifacts_metadata.exists?).to be_falsy + end + + it 'updates job' do + job.reload - it 'erases job content' do - expect(response).to have_gitlab_http_status(201) - expect(job).not_to have_trace - expect(job.artifacts_file.exists?).to be_falsy - expect(job.artifacts_metadata.exists?).to be_falsy + expect(job.erased_at).to be_truthy + expect(job.erased_by).to eq(user) + end end - it 'updates job' do - job.reload + context 'job is not erasable' do + let(:job) { create(:ci_build, :trace, project: project, pipeline: pipeline) } - expect(job.erased_at).to be_truthy - expect(job.erased_by).to eq(user) + it 'responds with forbidden' do + expect(response).to have_gitlab_http_status(403) + end end end - context 'job is not erasable' do - let(:job) { create(:ci_build, :trace, project: project, pipeline: pipeline) } + context 'when a developer erases a build' do + before do + project.add_developer(user) - it 'responds with forbidden' do - expect(response).to have_gitlab_http_status(403) + post api("/projects/#{project.id}/jobs/#{job.id}/erase", user) + end + + let(:job) { create(:ci_build, :trace, :artifacts, :success, project: project, pipeline: pipeline, user: owner) } + + context 'when the build was created by the developer' do + let(:owner) { user } + + it { expect(response).to have_gitlab_http_status(201) } + end + + context 'when the build was created by the other' do + let(:owner) { create(:user) } + + it { expect(response).to have_gitlab_http_status(403) } end end end |