summaryrefslogtreecommitdiff
path: root/spec/uploaders
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-03 00:05:59 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-03 00:05:59 +0000
commit427b23c12718bea233931431e7d9307881a960c0 (patch)
tree5e15672783c950a5e68dd89517d7888e652e01a7 /spec/uploaders
parent6d60f910762c1a92a07a4afaf1b26962f75ee4b6 (diff)
downloadgitlab-ce-427b23c12718bea233931431e7d9307881a960c0.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/uploaders')
-rw-r--r--spec/uploaders/file_uploader_spec.rb10
-rw-r--r--spec/uploaders/gitlab_uploader_spec.rb10
-rw-r--r--spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb18
3 files changed, 23 insertions, 15 deletions
diff --git a/spec/uploaders/file_uploader_spec.rb b/spec/uploaders/file_uploader_spec.rb
index 04206de3dc6..3c14edc7e0e 100644
--- a/spec/uploaders/file_uploader_spec.rb
+++ b/spec/uploaders/file_uploader_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe FileUploader do
let(:group) { create(:group, name: 'awesome') }
let(:project) { create(:project, :legacy_storage, namespace: group, name: 'project') }
- let(:uploader) { described_class.new(project) }
+ let(:uploader) { described_class.new(project, :avatar) }
let(:upload) { double(model: project, path: 'secret/foo.jpg') }
subject { uploader }
@@ -184,6 +184,14 @@ describe FileUploader do
end
end
+ describe '#replace_file_without_saving!' do
+ let(:replacement) { Tempfile.create('replacement.jpg') }
+
+ it 'replaces an existing file without changing its metadata' do
+ expect { subject.replace_file_without_saving! CarrierWave::SanitizedFile.new(replacement) }.not_to change { subject.upload }
+ end
+ end
+
context 'when remote file is used' do
let(:temp_file) { Tempfile.new("test") }
diff --git a/spec/uploaders/gitlab_uploader_spec.rb b/spec/uploaders/gitlab_uploader_spec.rb
index 3bee4875348..4425dd947c0 100644
--- a/spec/uploaders/gitlab_uploader_spec.rb
+++ b/spec/uploaders/gitlab_uploader_spec.rb
@@ -69,6 +69,16 @@ describe GitlabUploader do
end
end
+ describe '#replace_file_without_saving!' do
+ it 'allows file to be replaced without triggering any callbacks' do
+ new_file = CarrierWave::SanitizedFile.new(Tempfile.new)
+
+ expect(subject).not_to receive(:with_callbacks)
+
+ subject.replace_file_without_saving!(new_file)
+ end
+ end
+
describe '#open' do
context 'when trace is stored in File storage' do
context 'when file exists' do
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 6c2544d2efd..97e8a43f7fd 100644
--- a/spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb
+++ b/spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb
@@ -42,33 +42,23 @@ describe ObjectStorage::MigrateUploadsWorker, :sidekiq do
end
describe '.sanity_check!' do
- shared_examples 'raises a SanityCheckError' do
+ shared_examples 'raises a SanityCheckError' do |expected_message|
let(:mount_point) { nil }
it do
expect { described_class.sanity_check!(uploads, model_class, mount_point) }
- .to raise_error(described_class::SanityCheckError)
+ .to raise_error(described_class::SanityCheckError).with_message(expected_message)
end
end
- before do
- stub_const("WrongModel", Class.new)
- end
-
context 'uploader types mismatch' do
let!(:outlier) { create(:upload, uploader: 'GitlabUploader') }
- include_examples 'raises a SanityCheckError'
- end
-
- context 'model types mismatch' do
- let!(:outlier) { create(:upload, model_type: 'WrongModel') }
-
- include_examples 'raises a SanityCheckError'
+ include_examples 'raises a SanityCheckError', /Multiple uploaders found/
end
context 'mount point not found' do
- include_examples 'raises a SanityCheckError' do
+ include_examples 'raises a SanityCheckError', /Mount point [a-z:]+ not found in/ do
let(:mount_point) { :potato }
end
end