debian-mirror-gitlab/spec/support/shared_contexts/upload_type_check_shared_context.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
1.1 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
# Construct an `uploader` variable that is configured to `check_upload_type`
# with `mime_types` and `extensions`.
2020-04-08 14:13:33 +05:30
# @param uploader [CarrierWave::Uploader::Base] uploader with extension_whitelist method.
2022-08-27 11:52:29 +05:30
RSpec.shared_context 'ignore extension allowlist check' do
2020-04-08 14:13:33 +05:30
before do
allow(uploader).to receive(:extension_whitelist).and_return(nil)
2020-03-13 15:44:24 +05:30
end
end
2020-04-08 14:13:33 +05:30
# This works with a content_type_whitelist and content_type_blacklist type check.
# @param mime_type [String] mime type to forcibly detect.
RSpec.shared_context 'force content type detection to mime_type' do
2020-03-13 15:44:24 +05:30
before do
2021-04-01 16:36:13 +05:30
allow(Gitlab::Utils::MimeType).to receive(:from_io).and_return(mime_type)
2020-03-13 15:44:24 +05:30
end
end
2022-08-27 11:52:29 +05:30
def mock_upload(success = true)
allow(UploadService).to receive(:new).with(project, file).and_return(upload_service)
if success
allow(upload_service).to receive(:execute).and_return(uploader)
allow(uploader).to receive(:upload).and_return(upload)
allow(upload).to receive(:id).and_return(upload_id)
else
allow(upload_service).to receive(:execute).and_return(nil)
end
end