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-05-20 17:34:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 17:34:42 +0300
commit9f46488805e86b1bc341ea1620b866016c2ce5ed (patch)
treef9748c7e287041e37d6da49e0a29c9511dc34768 /spec/uploaders
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/uploaders')
-rw-r--r--spec/uploaders/content_type_whitelist_spec.rb18
-rw-r--r--spec/uploaders/design_management/design_v432x230_uploader_spec.rb86
-rw-r--r--spec/uploaders/records_uploads_spec.rb4
-rw-r--r--spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb12
4 files changed, 112 insertions, 8 deletions
diff --git a/spec/uploaders/content_type_whitelist_spec.rb b/spec/uploaders/content_type_whitelist_spec.rb
index 4689f83759d..32d030cdfee 100644
--- a/spec/uploaders/content_type_whitelist_spec.rb
+++ b/spec/uploaders/content_type_whitelist_spec.rb
@@ -3,16 +3,20 @@
require 'spec_helper'
describe ContentTypeWhitelist do
- class DummyUploader < CarrierWave::Uploader::Base
- include ContentTypeWhitelist::Concern
+ let_it_be(:model) { build_stubbed(:user) }
+ let!(:uploader) do
+ stub_const('DummyUploader', Class.new(CarrierWave::Uploader::Base))
+
+ DummyUploader.class_eval do
+ include ContentTypeWhitelist::Concern
- def content_type_whitelist
- %w[image/png image/jpeg]
+ def content_type_whitelist
+ %w[image/png image/jpeg]
+ end
end
- end
- let_it_be(:model) { build_stubbed(:user) }
- let_it_be(:uploader) { DummyUploader.new(model, :dummy) }
+ DummyUploader.new(model, :dummy)
+ end
context 'upload whitelisted file content type' do
let(:path) { File.join('spec', 'fixtures', 'rails_sample.jpg') }
diff --git a/spec/uploaders/design_management/design_v432x230_uploader_spec.rb b/spec/uploaders/design_management/design_v432x230_uploader_spec.rb
new file mode 100644
index 00000000000..8c62b6ad6a8
--- /dev/null
+++ b/spec/uploaders/design_management/design_v432x230_uploader_spec.rb
@@ -0,0 +1,86 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe DesignManagement::DesignV432x230Uploader do
+ include CarrierWave::Test::Matchers
+
+ let(:model) { create(:design_action, :with_image_v432x230) }
+ let(:upload) { create(:upload, :design_action_image_v432x230_upload, model: model) }
+
+ subject(:uploader) { described_class.new(model, :image_v432x230) }
+
+ it_behaves_like 'builds correct paths',
+ store_dir: %r[uploads/-/system/design_management/action/image_v432x230/],
+ upload_path: %r[uploads/-/system/design_management/action/image_v432x230/],
+ relative_path: %r[uploads/-/system/design_management/action/image_v432x230/],
+ absolute_path: %r[#{CarrierWave.root}/uploads/-/system/design_management/action/image_v432x230/]
+
+ context 'object_store is REMOTE' do
+ before do
+ stub_uploads_object_storage
+ end
+
+ include_context 'with storage', described_class::Store::REMOTE
+
+ it_behaves_like 'builds correct paths',
+ store_dir: %r[design_management/action/image_v432x230/],
+ upload_path: %r[design_management/action/image_v432x230/],
+ relative_path: %r[design_management/action/image_v432x230/]
+ end
+
+ describe "#migrate!" do
+ before do
+ uploader.store!(fixture_file_upload('spec/fixtures/dk.png'))
+ stub_uploads_object_storage
+ end
+
+ it_behaves_like 'migrates', to_store: described_class::Store::REMOTE
+ it_behaves_like 'migrates', from_store: described_class::Store::REMOTE, to_store: described_class::Store::LOCAL
+ end
+
+ it 'resizes images', :aggregate_failures do
+ image_loader = CarrierWave::Test::Matchers::ImageLoader
+ original_file = fixture_file_upload('spec/fixtures/dk.png')
+ uploader.store!(original_file)
+
+ expect(
+ image_loader.load_image(original_file.tempfile.path)
+ ).to have_attributes(
+ width: 460,
+ height: 322
+ )
+ expect(
+ image_loader.load_image(uploader.file.file)
+ ).to have_attributes(
+ width: 329,
+ height: 230
+ )
+ end
+
+ context 'accept whitelist file content type' do
+ # We need to feed through a valid path, but we force the parsed mime type
+ # in a stub below so we can set any path.
+ let_it_be(:path) { File.join('spec', 'fixtures', 'dk.png') }
+
+ where(:mime_type) { described_class::MIME_TYPE_WHITELIST }
+
+ with_them do
+ include_context 'force content type detection to mime_type'
+
+ it_behaves_like 'accepted carrierwave upload'
+ end
+ end
+
+ context 'upload non-whitelisted file content type' do
+ let_it_be(:path) { File.join('spec', 'fixtures', 'logo_sample.svg') }
+
+ it_behaves_like 'denied carrierwave upload'
+ end
+
+ context 'upload misnamed non-whitelisted file content type' do
+ let_it_be(:path) { File.join('spec', 'fixtures', 'not_a_png.png') }
+
+ it_behaves_like 'denied carrierwave upload'
+ end
+end
diff --git a/spec/uploaders/records_uploads_spec.rb b/spec/uploaders/records_uploads_spec.rb
index 71eff23c77c..1a3c416c74a 100644
--- a/spec/uploaders/records_uploads_spec.rb
+++ b/spec/uploaders/records_uploads_spec.rb
@@ -4,7 +4,9 @@ require 'spec_helper'
describe RecordsUploads do
let!(:uploader) do
- class RecordsUploadsExampleUploader < GitlabUploader
+ stub_const('RecordsUploadsExampleUploader', Class.new(GitlabUploader))
+
+ RecordsUploadsExampleUploader.class_eval do
include RecordsUploads::Concern
storage :file
diff --git a/spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb b/spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb
index fcb8f4e51b5..7bf8512a6fd 100644
--- a/spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb
+++ b/spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb
@@ -65,4 +65,16 @@ describe ObjectStorage::MigrateUploadsWorker do
end
end
end
+
+ context 'for DesignManagement::DesignV432x230Uploader' do
+ let(:model_class) { DesignManagement::Action }
+ let!(:design_actions) { create_list(:design_action, 10, :with_image_v432x230) }
+ let(:mounted_as) { :image_v432x230 }
+
+ before do
+ stub_uploads_object_storage(DesignManagement::DesignV432x230Uploader)
+ end
+
+ it_behaves_like 'uploads migration worker'
+ end
end