Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-16 06:09:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-16 06:09:14 +0300
commit78fe72d153260c355fdfd533b125026cce310da7 (patch)
tree0d90106443bea87cc24e2834273ae6c8dcac0260 /spec/support/shared_examples/uploaders
parent88797b994a7dfd9bfab2a5d5431f088f17078b9f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/shared_examples/uploaders')
-rw-r--r--spec/support/shared_examples/uploaders/upload_type_shared_examples.rb64
1 files changed, 0 insertions, 64 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 99da2a14bb6..81ac6bd94db 100644
--- a/spec/support/shared_examples/uploaders/upload_type_shared_examples.rb
+++ b/spec/support/shared_examples/uploaders/upload_type_shared_examples.rb
@@ -26,67 +26,3 @@ shared_examples 'accepted carrierwave upload' 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)
-end
-
-RSpec.shared_examples 'upload passes content type check' do
- it 'does not raise error' do
- expect { check_content_matches_extension! }.not_to raise_error
- end
-end
-
-RSpec.shared_examples 'upload fails content type check' do
- it 'raises error' do
- expect { check_content_matches_extension! }.to raise_error(CarrierWave::IntegrityError)
- end
-end
-
-def upload_type_checked_filenames(filenames)
- Array(filenames).each do |filename|
- # Feed the uploader "some" content.
- path = File.join('spec', 'fixtures', 'dk.png')
- file = File.new(path, 'r')
- # Rename the file with what we want.
- allow(file).to receive(:path).and_return(filename)
-
- # Force the content type to match the extension type.
- mime_type = MimeMagic.by_path(filename)
- allow(MimeMagic).to receive(:by_magic).and_return(mime_type)
-
- uploaded_file = Rack::Test::UploadedFile.new(file, original_filename: filename)
- uploader.cache!(uploaded_file)
- end
-end
-
-def upload_type_checked_fixtures(upload_fixtures)
- upload_fixtures = Array(upload_fixtures)
- upload_fixtures.each do |upload_fixture|
- path = File.join('spec', 'fixtures', upload_fixture)
- uploader.cache!(fixture_file_upload(path))
- end
-end
-
-RSpec.shared_examples 'type checked uploads' do |upload_fixtures = nil, filenames: nil|
- it 'check type' do
- upload_fixtures = Array(upload_fixtures)
- filenames = Array(filenames)
-
- times = upload_fixtures.length + filenames.length
- expect(uploader).to receive(:check_content_matches_extension!).exactly(times).times
-
- upload_type_checked_fixtures(upload_fixtures) unless upload_fixtures.empty?
- upload_type_checked_filenames(filenames) unless filenames.empty?
- end
-end
-
-RSpec.shared_examples 'skipped type checked uploads' do |upload_fixtures = nil, filenames: nil|
- it 'skip type check' do
- expect(uploader).not_to receive(:check_content_matches_extension!)
-
- upload_type_checked_fixtures(upload_fixtures) if upload_fixtures
- upload_type_checked_filenames(filenames) if filenames
- end
-end