Use AR callbacks as suggested by:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4964#note_12744656
This commit is contained in:
parent
1bc0d732f6
commit
9d8dca08e4
|
@ -19,6 +19,7 @@ module Ci
|
||||||
|
|
||||||
acts_as_taggable
|
acts_as_taggable
|
||||||
|
|
||||||
|
before_save :update_artifacts_size, if: :artifacts_file_changed?
|
||||||
before_destroy { project }
|
before_destroy { project }
|
||||||
|
|
||||||
after_create :execute_hooks
|
after_create :execute_hooks
|
||||||
|
@ -340,7 +341,6 @@ module Ci
|
||||||
def erase_artifacts!
|
def erase_artifacts!
|
||||||
remove_artifacts_file!
|
remove_artifacts_file!
|
||||||
remove_artifacts_metadata!
|
remove_artifacts_metadata!
|
||||||
self.artifacts_size = nil
|
|
||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -381,6 +381,10 @@ module Ci
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def update_artifacts_size
|
||||||
|
self.artifacts_size = artifacts_file.size
|
||||||
|
end
|
||||||
|
|
||||||
def erase_trace!
|
def erase_trace!
|
||||||
self.trace = nil
|
self.trace = nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -147,7 +147,6 @@ module Ci
|
||||||
build.artifacts_file = artifacts
|
build.artifacts_file = artifacts
|
||||||
build.artifacts_metadata = metadata
|
build.artifacts_metadata = metadata
|
||||||
build.artifacts_expire_in = params['expire_in']
|
build.artifacts_expire_in = params['expire_in']
|
||||||
build.artifacts_size = artifacts.size
|
|
||||||
|
|
||||||
if build.save
|
if build.save
|
||||||
present(build, with: Entities::BuildDetails)
|
present(build, with: Entities::BuildDetails)
|
||||||
|
|
|
@ -476,13 +476,17 @@ describe Ci::API::API do
|
||||||
|
|
||||||
describe 'DELETE /builds/:id/artifacts' do
|
describe 'DELETE /builds/:id/artifacts' do
|
||||||
let(:build) { create(:ci_build, :artifacts) }
|
let(:build) { create(:ci_build, :artifacts) }
|
||||||
before { delete delete_url, token: build.token }
|
|
||||||
|
before do
|
||||||
|
delete delete_url, token: build.token
|
||||||
|
build.reload
|
||||||
|
end
|
||||||
|
|
||||||
it 'should remove build artifacts' do
|
it 'should remove build artifacts' do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
expect(build.artifacts_file.exists?).to be_falsy
|
expect(build.artifacts_file.exists?).to be_falsy
|
||||||
expect(build.artifacts_metadata.exists?).to be_falsy
|
expect(build.artifacts_metadata.exists?).to be_falsy
|
||||||
expect(build.artifacts_size).to be_falsy
|
expect(build.artifacts_size).to eq(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue