debian-mirror-gitlab/spec/uploaders/personal_file_uploader_spec.rb

56 lines
1.6 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
2018-03-17 18:26:18 +05:30
IDENTIFIER = %r{\h+/\S+}
2017-08-17 22:00:37 +05:30
describe PersonalFileUploader do
2018-03-17 18:26:18 +05:30
let(:model) { create(:personal_snippet) }
let(:uploader) { described_class.new(model) }
let(:upload) { create(:upload, :personal_snippet_upload) }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
subject { uploader }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
it_behaves_like 'builds correct paths',
store_dir: %r[uploads/-/system/personal_snippet/\d+],
upload_path: IDENTIFIER,
absolute_path: %r[#{CarrierWave.root}/uploads/-/system/personal_snippet/\d+/#{IDENTIFIER}]
2017-08-17 22:00:37 +05:30
2018-05-09 12:01:36 +05:30
context "object_store is REMOTE" do
before do
stub_uploads_object_storage
end
include_context 'with storage', described_class::Store::REMOTE
it_behaves_like 'builds correct paths',
store_dir: %r[\d+/\h+],
upload_path: IDENTIFIER
end
2017-08-17 22:00:37 +05:30
describe '#to_h' do
2018-03-17 18:26:18 +05:30
before do
subject.instance_variable_set(:@secret, 'secret')
end
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
it 'is correct' do
2017-08-17 22:00:37 +05:30
allow(uploader).to receive(:file).and_return(double(extension: 'txt', filename: 'file_name'))
2018-03-17 18:26:18 +05:30
expected_url = "/uploads/-/system/personal_snippet/#{model.id}/secret/file_name"
2017-08-17 22:00:37 +05:30
expect(uploader.to_h).to eq(
alt: 'file_name',
url: expected_url,
markdown: "[file_name](#{expected_url})"
)
end
end
2018-05-09 12:01:36 +05:30
describe "#migrate!" do
before do
uploader.store!(fixture_file_upload(Rails.root.join('spec/fixtures/doc_sample.txt')))
stub_uploads_object_storage
end
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
end
2017-08-17 22:00:37 +05:30
end