2017-12-06 11:36:11 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-02-02 13:59:43 +00:00
|
|
|
IDENTIFIER = %r{\h+/\S+}
|
|
|
|
|
2017-12-06 11:36:11 +00:00
|
|
|
describe NamespaceFileUploader do
|
|
|
|
let(:group) { build_stubbed(:group) }
|
|
|
|
let(:uploader) { described_class.new(group) }
|
2018-02-02 13:59:43 +00:00
|
|
|
let(:upload) { create(:upload, :namespace_upload, model: group) }
|
|
|
|
|
|
|
|
subject { uploader }
|
2017-12-06 11:36:11 +00:00
|
|
|
|
2018-02-02 13:59:43 +00:00
|
|
|
it_behaves_like 'builds correct paths',
|
|
|
|
store_dir: %r[uploads/-/system/namespace/\d+],
|
|
|
|
upload_path: IDENTIFIER,
|
|
|
|
absolute_path: %r[#{CarrierWave.root}/uploads/-/system/namespace/\d+/#{IDENTIFIER}]
|
|
|
|
|
|
|
|
context "object_store is REMOTE" do
|
|
|
|
before do
|
|
|
|
stub_uploads_object_storage
|
2017-12-06 11:36:11 +00:00
|
|
|
end
|
|
|
|
|
2018-02-02 13:59:43 +00:00
|
|
|
include_context 'with storage', described_class::Store::REMOTE
|
2017-12-06 11:36:11 +00:00
|
|
|
|
2018-02-02 13:59:43 +00:00
|
|
|
it_behaves_like 'builds correct paths',
|
|
|
|
store_dir: %r[namespace/\d+/\h+],
|
|
|
|
upload_path: IDENTIFIER
|
|
|
|
end
|
|
|
|
|
2018-08-20 12:46:22 +00:00
|
|
|
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
|
|
|
|
|
2018-09-10 17:03:33 +00:00
|
|
|
describe '#workhorse_local_upload_path' do
|
|
|
|
it 'returns the correct path in uploads directory' do
|
|
|
|
expect(described_class.workhorse_local_upload_path).to end_with('/uploads/tmp/uploads')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-02 13:59:43 +00:00
|
|
|
describe "#migrate!" do
|
|
|
|
before do
|
2018-06-05 21:18:06 +00:00
|
|
|
uploader.store!(fixture_file_upload(File.join('spec/fixtures/doc_sample.txt')))
|
2018-02-02 13:59:43 +00:00
|
|
|
stub_uploads_object_storage
|
2017-12-06 11:36:11 +00:00
|
|
|
end
|
2018-02-02 13:59:43 +00:00
|
|
|
|
|
|
|
it_behaves_like "migrates", to_store: described_class::Store::REMOTE
|
|
|
|
it_behaves_like "migrates", from_store: described_class::Store::REMOTE, to_store: described_class::Store::LOCAL
|
2017-12-06 11:36:11 +00:00
|
|
|
end
|
|
|
|
end
|