diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-11-12 16:27:28 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-11-12 16:27:28 +0100 |
commit | 5b45cd246373f18bf678dbdecad589733cfec8b0 (patch) | |
tree | 8f8320f4c7251790b2eb352d9df20e10e1df0dcf /spec | |
parent | d15c9ae37b29c561a68309e8d81558016ffdb261 (diff) | |
download | gitlab-ce-5b45cd246373f18bf678dbdecad589733cfec8b0.tar.gz |
Implement MVC for Pipeline deletion API
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/pipelines_spec.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/requests/api/pipelines_spec.rb b/spec/requests/api/pipelines_spec.rb index f0e1992bccd..68de3068568 100644 --- a/spec/requests/api/pipelines_spec.rb +++ b/spec/requests/api/pipelines_spec.rb @@ -438,6 +438,53 @@ describe API::Pipelines do end end + describe 'DELETE /projects/:id/pipelines/:pipeline_id' do + context 'authorized user' do + it 'deletes the pipeline' do + delete api("/projects/#{project.id}/pipelines/#{pipeline.id}", user) + + expect(response).to have_gitlab_http_status(204) + expect { pipeline.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + + it 'returns 404 when it does not exist' do + delete api("/projects/#{project.id}/pipelines/123456", user) + + expect(response).to have_gitlab_http_status(404) + expect(json_response['message']).to eq '404 Not found' + end + + it 'logs an audit event' do + expect { delete api("/projects/#{project.id}/pipelines/#{pipeline.id}", user) }.to change { SecurityEvent.count }.by(1) + end + + context 'when the pipeline has jobs' do + let!(:pipeline) do + create(:ci_pipeline, project: project, sha: project.commit.id, + ref: project.default_branch, user: user) + end + + let!(:build) { create(:ci_build, project: project, pipeline: pipeline) } + + it 'deletes associated jobs' do + delete api("/projects/#{project.id}/pipelines/#{pipeline.id}", user) + + expect(response).to have_gitlab_http_status(204) + expect { build.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + end + end + + context 'unauthorized user' do + it 'should not return a project pipeline' do + get api("/projects/#{project.id}/pipelines/#{pipeline.id}", non_member) + + expect(response).to have_gitlab_http_status(404) + expect(json_response['message']).to eq '404 Project Not Found' + end + end + end + describe 'POST /projects/:id/pipelines/:pipeline_id/retry' do context 'authorized user' do let!(:pipeline) do |