BigW Consortium Gitlab

Commit 21152d7d by 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 @@
= link_to "Retry", @build.retry_url, class: 'btn btn-sm btn-primary', method: :post
- 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
= icon('eraser')
Erase
......
......@@ -617,7 +617,7 @@ Rails.application.routes.draw do
get :status
post :cancel
post :retry
put :erase
delete :erase
end
resource :artifacts, only: [] do
......
......@@ -156,6 +156,7 @@ module Ci
build = Ci::Build.find_by_id(params[:id])
not_found! unless build
authenticate_build_token!(build)
build.remove_artifacts_file!
build.remove_artifacts_metadata!
end
......@@ -168,11 +169,12 @@ module Ci
# Headers:
# BUILD-TOKEN (required) - The build authorization token, the same as token
# Example Request:
# PUT /builds/:id/erase
put ':id/erase' do
# DELETE /builds/:id/content
delete ':id/content' do
build = Ci::Build.find_by_id(params[:id])
not_found! unless build
authenticate_build_token!(build)
build.erase!
end
end
......
......@@ -62,14 +62,13 @@ FactoryGirl.define do
trait :artifacts do
after(:create) do |build, _|
build.artifacts_file =
fixture_file_upload(Rails.root +
'spec/fixtures/ci_build_artifacts.zip',
'application/zip')
fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts.zip'),
'application/zip')
build.artifacts_metadata =
fixture_file_upload(Rails.root +
'spec/fixtures/ci_build_artifacts_metadata.gz',
'application/x-gzip')
fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts_metadata.gz'),
' application/x-gzip')
build.save!
end
end
......
......@@ -497,6 +497,5 @@ describe Ci::Build, models: true do
expect(@build2.merge_request.id).to eq(@merge_request.id)
end
end
end
end
......@@ -148,6 +148,24 @@ describe Ci::API::API do
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
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') }
......
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