2017-05-01 09:14:35 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
IDENTIFIER = %r{\h+/\S+}
|
|
|
|
|
2017-05-01 09:14:35 -04:00
|
|
|
describe PersonalFileUploader do
|
2018-01-29 12:57:34 -05:00
|
|
|
let(:model) { create(:personal_snippet) }
|
|
|
|
let(:uploader) { described_class.new(model) }
|
|
|
|
let(:upload) { create(:upload, :personal_snippet_upload) }
|
2017-05-01 09:14:35 -04:00
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
subject { uploader }
|
2017-05-01 09:14:35 -04:00
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
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-05-01 09:14:35 -04:00
|
|
|
|
|
|
|
describe '#to_h' do
|
2018-01-29 12:57:34 -05:00
|
|
|
before do
|
|
|
|
subject.instance_variable_set(:@secret, 'secret')
|
|
|
|
end
|
2017-05-01 09:14:35 -04:00
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
it 'is correct' do
|
2017-05-01 09:14:35 -04:00
|
|
|
allow(uploader).to receive(:file).and_return(double(extension: 'txt', filename: 'file_name'))
|
2018-01-29 12:57:34 -05:00
|
|
|
expected_url = "/uploads/-/system/personal_snippet/#{model.id}/secret/file_name"
|
2017-05-01 09:14:35 -04:00
|
|
|
|
|
|
|
expect(uploader.to_h).to eq(
|
|
|
|
alt: 'file_name',
|
|
|
|
url: expected_url,
|
|
|
|
markdown: "[file_name](#{expected_url})"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|