Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz.bizon@ntsn.pl>2016-02-03 13:24:44 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-02-19 19:24:59 +0300
commit21152d7d51815622fd3cbb93836cb8fa7b753ec8 (patch)
treecdc920f90683104132c924259dd8b060887338f8
parent6ca99bd899322ff4ada84f119907eb0210485482 (diff)
Use DELETE verb for erasing a build content
Also added API specs for that
-rw-r--r--app/views/projects/builds/show.html.haml2
-rw-r--r--config/routes.rb2
-rw-r--r--lib/ci/api/builds.rb6
-rw-r--r--spec/factories/ci/builds.rb11
-rw-r--r--spec/models/build_spec.rb1
-rw-r--r--spec/requests/ci/api/builds_spec.rb18
6 files changed, 29 insertions, 11 deletions
diff --git a/app/views/projects/builds/show.html.haml b/app/views/projects/builds/show.html.haml
index 719709df1d5..624fe81dc85 100644
--- a/app/views/projects/builds/show.html.haml
+++ b/app/views/projects/builds/show.html.haml
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index 94a9d378be0..118fdf9c28b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -617,7 +617,7 @@ Rails.application.routes.draw do
get :status
post :cancel
post :retry
- put :erase
+ delete :erase
end
resource :artifacts, only: [] do
diff --git a/lib/ci/api/builds.rb b/lib/ci/api/builds.rb
index 23e909df366..2d3d6c75f00 100644
--- a/lib/ci/api/builds.rb
+++ b/lib/ci/api/builds.rb
@@ -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
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb
index 8305bf364d4..af6e27569c0 100644
--- a/spec/factories/ci/builds.rb
+++ b/spec/factories/ci/builds.rb
@@ -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
diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb
index a0cf5cfacc4..bcf4a156346 100644
--- a/spec/models/build_spec.rb
+++ b/spec/models/build_spec.rb
@@ -497,6 +497,5 @@ describe Ci::Build, models: true do
expect(@build2.merge_request.id).to eq(@merge_request.id)
end
end
-
end
end
diff --git a/spec/requests/ci/api/builds_spec.rb b/spec/requests/ci/api/builds_spec.rb
index 01b369720ca..e1042bde8d5 100644
--- a/spec/requests/ci/api/builds_spec.rb
+++ b/spec/requests/ci/api/builds_spec.rb
@@ -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') }