diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-03 00:07:38 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-03 00:07:38 +0300 |
commit | 9d54184f308893338967b18874dedebf38acf89e (patch) | |
tree | 100e32c6d4b34deac52d9e98a083361d89804b50 /spec/support/shared_contexts | |
parent | d5b5f5e6e1474d5526add9033c9754b8e395841f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/shared_contexts')
-rw-r--r-- | spec/support/shared_contexts/upload_type_check_shared_context.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/support/shared_contexts/upload_type_check_shared_context.rb b/spec/support/shared_contexts/upload_type_check_shared_context.rb new file mode 100644 index 00000000000..04c97500dd6 --- /dev/null +++ b/spec/support/shared_contexts/upload_type_check_shared_context.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +# Construct an `uploader` variable that is configured to `check_upload_type` +# with `mime_types` and `extensions`. +shared_context 'uploader with type check' do + let(:uploader_class) do + Class.new(GitlabUploader) do + include UploadTypeCheck::Concern + storage :file + end + end + + let(:mime_types) { nil } + let(:extensions) { nil } + let(:uploader) do + uploader_class.class_exec(mime_types, extensions) do |mime_types, extensions| + check_upload_type mime_types: mime_types, extensions: extensions + end + uploader_class.new(build_stubbed(:user)) + end +end + +shared_context 'stubbed MimeMagic mime type detection' do + let(:mime_type) { '' } + let(:magic_mime) { mime_type } + let(:ext_mime) { mime_type } + before do + magic_mime_obj = MimeMagic.new(magic_mime) + ext_mime_obj = MimeMagic.new(ext_mime) + allow(MimeMagic).to receive(:by_magic).with(anything).and_return(magic_mime_obj) + allow(MimeMagic).to receive(:by_path).with(anything).and_return(ext_mime_obj) + end +end |