Commit 718a823f authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'sh-fix-dependency-proxy-object-storage' into 'master'

Fix dependency proxy not working with object storage

Closes #231563

See merge request gitlab-org/gitlab!37878
parents e3a72156 c10e910d
---
title: Fix dependency proxy not working with object storage
merge_request: 37878
author:
type: fixed
......@@ -9,6 +9,8 @@ class DependencyProxy::Blob < ApplicationRecord
mount_uploader :file, DependencyProxy::FileUploader
after_save :update_file_store, if: :saved_change_to_file?
def self.total_size
sum(:size)
end
......@@ -16,4 +18,10 @@ class DependencyProxy::Blob < ApplicationRecord
def self.find_or_build(file_name)
find_or_initialize_by(file_name: file_name)
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
......@@ -36,4 +36,30 @@ RSpec.describe DependencyProxy::Blob, type: :model do
expect(described_class.find_or_build(blob.file_name)).to eq(blob)
end
end
describe 'file is being stored' do
subject { create(:dependency_proxy_blob) }
context 'when existing object has local store' do
it 'is stored locally' do
expect(subject.file_store).to be(ObjectStorage::Store::LOCAL)
expect(subject.file).to be_file_storage
expect(subject.file.object_store).to eq(ObjectStorage::Store::LOCAL)
end
end
context 'when direct upload is enabled' do
before do
stub_dependency_proxy_object_storage(direct_upload: true)
end
context 'when file is stored' do
it 'is stored remotely' do
expect(subject.file_store).to eq(ObjectStorage::Store::REMOTE)
expect(subject.file).not_to be_file_storage
expect(subject.file.object_store).to eq(ObjectStorage::Store::REMOTE)
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