diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 18:09:28 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 18:09:28 +0000 |
commit | ce8a0b90849ac5d1895e741c023432930f24d724 (patch) | |
tree | dbdc97de542cdbe18a2fc8b1a6b64ac0673ed3d3 /spec/support/shared_examples | |
parent | dc889678d1de8c09310b2f8f9742bb6c78a6f1a4 (diff) | |
download | gitlab-ce-ce8a0b90849ac5d1895e741c023432930f24d724.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/shared_examples')
-rw-r--r-- | spec/support/shared_examples/uploaders/upload_type_shared_examples.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/support/shared_examples/uploaders/upload_type_shared_examples.rb b/spec/support/shared_examples/uploaders/upload_type_shared_examples.rb index 6e5075e135d..99da2a14bb6 100644 --- a/spec/support/shared_examples/uploaders/upload_type_shared_examples.rb +++ b/spec/support/shared_examples/uploaders/upload_type_shared_examples.rb @@ -1,5 +1,32 @@ # frozen_string_literal: true +# @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) + end +end + +# @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) } + + before do + uploader.remove! + end + + it 'will accept upload' do + expect { uploader.cache!(fixture_file) }.not_to raise_exception + end + + it 'will cache uploaded file' do + expect { uploader.cache!(fixture_file) }.to change { uploader.file }.from(nil).to(kind_of(CarrierWave::SanitizedFile)) + end +end + def check_content_matches_extension!(file = double(read: nil, path: '')) magic_file = UploadTypeCheck::MagicFile.new(file) uploader.check_content_matches_extension!(magic_file) |