Commit 21152d7d authored by Grzegorz Bizon's avatar Grzegorz Bizon Committed by Grzegorz Bizon

Use DELETE verb for erasing a build content

Also added API specs for that
parent 6ca99bd8
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
= link_to "Retry", @build.retry_url, class: 'btn btn-sm btn-primary', method: :post = link_to "Retry", @build.retry_url, class: 'btn btn-sm btn-primary', method: :post
- if @build.eraseable? - if @build.eraseable?
= link_to @build.erase_url, class: 'btn btn-sm btn-warning', method: :put, = link_to @build.erase_url, class: 'btn btn-sm btn-warning', method: :delete,
data: { confirm: 'Are you sure you want to erase this build?' } do data: { confirm: 'Are you sure you want to erase this build?' } do
= icon('eraser') = icon('eraser')
Erase Erase
......
...@@ -617,7 +617,7 @@ Rails.application.routes.draw do ...@@ -617,7 +617,7 @@ Rails.application.routes.draw do
get :status get :status
post :cancel post :cancel
post :retry post :retry
put :erase delete :erase
end end
resource :artifacts, only: [] do resource :artifacts, only: [] do
......
...@@ -156,6 +156,7 @@ module Ci ...@@ -156,6 +156,7 @@ module Ci
build = Ci::Build.find_by_id(params[:id]) build = Ci::Build.find_by_id(params[:id])
not_found! unless build not_found! unless build
authenticate_build_token!(build) authenticate_build_token!(build)
build.remove_artifacts_file! build.remove_artifacts_file!
build.remove_artifacts_metadata! build.remove_artifacts_metadata!
end end
...@@ -168,11 +169,12 @@ module Ci ...@@ -168,11 +169,12 @@ module Ci
# Headers: # Headers:
# BUILD-TOKEN (required) - The build authorization token, the same as token # BUILD-TOKEN (required) - The build authorization token, the same as token
# Example Request: # Example Request:
# PUT /builds/:id/erase # DELETE /builds/:id/content
put ':id/erase' do delete ':id/content' do
build = Ci::Build.find_by_id(params[:id]) build = Ci::Build.find_by_id(params[:id])
not_found! unless build not_found! unless build
authenticate_build_token!(build) authenticate_build_token!(build)
build.erase! build.erase!
end end
end end
......
...@@ -62,14 +62,13 @@ FactoryGirl.define do ...@@ -62,14 +62,13 @@ FactoryGirl.define do
trait :artifacts do trait :artifacts do
after(:create) do |build, _| after(:create) do |build, _|
build.artifacts_file = build.artifacts_file =
fixture_file_upload(Rails.root + fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts.zip'),
'spec/fixtures/ci_build_artifacts.zip', 'application/zip')
'application/zip')
build.artifacts_metadata = build.artifacts_metadata =
fixture_file_upload(Rails.root + fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts_metadata.gz'),
'spec/fixtures/ci_build_artifacts_metadata.gz', ' application/x-gzip')
'application/x-gzip')
build.save! build.save!
end end
end end
......
...@@ -497,6 +497,5 @@ describe Ci::Build, models: true do ...@@ -497,6 +497,5 @@ describe Ci::Build, models: true do
expect(@build2.merge_request.id).to eq(@merge_request.id) expect(@build2.merge_request.id).to eq(@merge_request.id)
end end
end end
end end
end end
...@@ -148,6 +148,24 @@ describe Ci::API::API do ...@@ -148,6 +148,24 @@ describe Ci::API::API do
end end
end end
describe 'DELETE /builds/:id/content' do
before { delete ci_api("/builds/#{build.id}/content"), token: build.token }
let!(:build) { create(:ci_build_with_trace, :artifacts, :success) }
it 'should respond with valid status' do
expect(response.status).to eq 200
end
it 'should remove build artifacts' do
expect(build.artifacts_file.exists?).to be_falsy
expect(build.artifacts_metadata.exists?).to be_falsy
end
it 'should remove build trace' do
expect(build.trace).to be_empty
end
end
context "Artifacts" do context "Artifacts" do
let(:file_upload) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') } let(:file_upload) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }
let(:file_upload2) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/gif') } let(:file_upload2) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/gif') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment