Commit ad12e626 authored by Maxime Orefice's avatar Maxime Orefice

Use FileStoreMounter in PipelineArtifact

This MR uses our new concern which extracts the logic
to update the file store column after record creation.
parent c86db37e
...@@ -6,6 +6,7 @@ module Ci ...@@ -6,6 +6,7 @@ module Ci
class PipelineArtifact < ApplicationRecord class PipelineArtifact < ApplicationRecord
extend Gitlab::Ci::Model extend Gitlab::Ci::Model
include Artifactable include Artifactable
include FileStoreMounter
FILE_STORE_SUPPORTED = [ FILE_STORE_SUPPORTED = [
ObjectStorage::Store::LOCAL, ObjectStorage::Store::LOCAL,
...@@ -22,9 +23,8 @@ module Ci ...@@ -22,9 +23,8 @@ module Ci
validates :size, presence: true, numericality: { less_than_or_equal_to: FILE_SIZE_LIMIT } validates :size, presence: true, numericality: { less_than_or_equal_to: FILE_SIZE_LIMIT }
validates :file_type, presence: true validates :file_type, presence: true
mount_uploader :file, Ci::PipelineArtifactUploader mount_file_store_uploader Ci::PipelineArtifactUploader
before_save :set_size, if: :file_changed? before_save :set_size, if: :file_changed?
after_save :update_file_store, if: :saved_change_to_file?
enum file_type: { enum file_type: {
code_coverage: 1 code_coverage: 1
...@@ -33,11 +33,5 @@ module Ci ...@@ -33,11 +33,5 @@ module Ci
def set_size def set_size
self.size = file.size self.size = file.size
end end
def update_file_store
# The file.object_store is set during `uploader.store!`
# which happens after object is inserted/updated
self.update_column(:file_store, file.object_store)
end
end end
end end
...@@ -66,10 +66,16 @@ RSpec.describe Ci::PipelineArtifact, type: :model do ...@@ -66,10 +66,16 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
subject { create(:ci_pipeline_artifact) } subject { create(:ci_pipeline_artifact) }
context 'when existing object has local store' do context 'when existing object has local store' do
it 'is stored locally' do it_behaves_like 'mounted file in local store'
expect(subject.file_store).to be(ObjectStorage::Store::LOCAL) end
expect(subject.file).to be_file_storage
expect(subject.file.object_store).to eq(ObjectStorage::Store::LOCAL) context 'when direct upload is enabled' do
before do
stub_artifacts_object_storage(Ci::PipelineArtifactUploader, direct_upload: true)
end
context 'when file is stored' do
it_behaves_like 'mounted file in object store'
end end
end end
end end
......
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