Fix NamespaceUploader.base_dir for remote uploads

This commit is contained in:
Jarka Kadlecová 2018-08-20 14:46:22 +02:00
parent 3c80adf5c8
commit 0a1c805d85
3 changed files with 28 additions and 9 deletions

View File

@ -6,8 +6,15 @@ class NamespaceFileUploader < FileUploader
options.storage_path
end
def self.base_dir(model, _store = nil)
File.join(options.base_dir, 'namespace', model_path_segment(model))
def self.base_dir(model, store = nil)
base_dirs(model)[store || Store::LOCAL]
end
def self.base_dirs(model)
{
Store::LOCAL => File.join(options.base_dir, 'namespace', model_path_segment(model)),
Store::REMOTE => File.join('namespace', model_path_segment(model))
}
end
def self.model_path_segment(model)
@ -18,11 +25,4 @@ class NamespaceFileUploader < FileUploader
def store_dir
store_dirs[object_store]
end
def store_dirs
{
Store::LOCAL => File.join(base_dir, dynamic_segment),
Store::REMOTE => File.join('namespace', self.class.model_path_segment(model), dynamic_segment)
}
end
end

View File

@ -0,0 +1,5 @@
---
title: Fix NamespaceUploader.base_dir for remote uploads
merge_request:
author:
type: fixed

View File

@ -26,6 +26,20 @@ describe NamespaceFileUploader do
upload_path: IDENTIFIER
end
context '.base_dir' do
it 'returns local storage base_dir without store param' do
expect(described_class.base_dir(group)).to eq("uploads/-/system/namespace/#{group.id}")
end
it 'returns local storage base_dir when store param is Store::LOCAL' do
expect(described_class.base_dir(group, ObjectStorage::Store::LOCAL)).to eq("uploads/-/system/namespace/#{group.id}")
end
it 'returns remote base_dir when store param is Store::REMOTE' do
expect(described_class.base_dir(group, ObjectStorage::Store::REMOTE)).to eq("namespace/#{group.id}")
end
end
describe "#migrate!" do
before do
uploader.store!(fixture_file_upload(File.join('spec/fixtures/doc_sample.txt')))