2017-05-01 09:14:35 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe PersonalFileUploader do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:uploader) { described_class.new(build_stubbed(:project)) }
|
2017-05-01 09:14:35 -04:00
|
|
|
let(:snippet) { create(:personal_snippet) }
|
|
|
|
|
|
|
|
describe '.absolute_path' do
|
|
|
|
it 'returns the correct absolute path by building it dynamically' do
|
|
|
|
upload = double(model: snippet, path: 'secret/foo.jpg')
|
|
|
|
|
|
|
|
dynamic_segment = "personal_snippet/#{snippet.id}"
|
|
|
|
|
2017-08-07 13:43:11 -04:00
|
|
|
expect(described_class.absolute_path(upload)).to end_with("/-/system/#{dynamic_segment}/secret/foo.jpg")
|
2017-05-01 09:14:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#to_h' do
|
|
|
|
it 'returns the hass' do
|
|
|
|
uploader = described_class.new(snippet, 'secret')
|
|
|
|
|
|
|
|
allow(uploader).to receive(:file).and_return(double(extension: 'txt', filename: 'file_name'))
|
2017-08-07 13:43:11 -04:00
|
|
|
expected_url = "/uploads/-/system/personal_snippet/#{snippet.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
|