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/requests/api/jobs_spec.rb | |
parent | d89c18901bde510da2668e676b3bf2f1e21deef2 (diff) |
Improve spec
Diffstat (limited to 'spec/requests/api/jobs_spec.rb')
-rw-r--r-- | spec/requests/api/jobs_spec.rb | 62 |
1 files changed, 43 insertions, 19 deletions
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 |