debian-mirror-gitlab/spec/support/shared_examples/uploaders/upload_type_shared_examples.rb

41 lines
1.5 KiB
Ruby
Raw Normal View History

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.
2020-07-28 23:09:34 +05:30
RSpec.shared_examples 'denied carrierwave upload' do
2020-04-08 14:13:33 +05:30
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.
2020-07-28 23:09:34 +05:30
RSpec.shared_examples 'accepted carrierwave upload' do
2020-04-08 14:13:33 +05:30
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
2020-07-28 23:09:34 +05:30
RSpec.shared_examples 'upload with content type' do |content_type|
2020-04-08 14:13:33 +05:30
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