2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
# @param path [String] the path to file to upload. E.g. File.join('spec', 'fixtures', 'sanitized.svg')
|
|
|
|
# @param uploader [CarrierWave::Uploader::Base] uploader to handle the upload.
|
|
|
|
shared_examples 'denied carrierwave upload' do
|
|
|
|
it 'will deny upload' do
|
|
|
|
fixture_file = fixture_file_upload(path)
|
|
|
|
expect { uploader.cache!(fixture_file) }.to raise_exception(CarrierWave::IntegrityError)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
# @param path [String] the path to file to upload. E.g. File.join('spec', 'fixtures', 'sanitized.svg')
|
|
|
|
# @param uploader [CarrierWave::Uploader::Base] uploader to handle the upload.
|
|
|
|
shared_examples 'accepted carrierwave upload' do
|
|
|
|
let(:fixture_file) { fixture_file_upload(path) }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
before do
|
|
|
|
uploader.remove!
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it 'will accept upload' do
|
|
|
|
expect { uploader.cache!(fixture_file) }.not_to raise_exception
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it 'will cache uploaded file' do
|
|
|
|
expect { uploader.cache!(fixture_file) }.to change { uploader.file }.from(nil).to(kind_of(CarrierWave::SanitizedFile))
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
# @param path [String] the path to file to upload. E.g. File.join('spec', 'fixtures', 'sanitized.svg')
|
|
|
|
# @param uploader [CarrierWave::Uploader::Base] uploader to handle the upload.
|
|
|
|
# @param content_type [String] the upload file content type after cache
|
|
|
|
shared_examples 'upload with content type' do |content_type|
|
|
|
|
let(:fixture_file) { fixture_file_upload(path, content_type) }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it 'will not change upload file content type' do
|
|
|
|
uploader.cache!(fixture_file)
|
|
|
|
expect(uploader.file.content_type).to eq(content_type)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|