Commit 183b4233 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Improved specs, error messages and documentation

parent 81f821d3
...@@ -99,10 +99,10 @@ class GitlabUploader < CarrierWave::Uploader::Base ...@@ -99,10 +99,10 @@ class GitlabUploader < CarrierWave::Uploader::Base
end end
end end
# Used to replace an existing upload with the informed file without modifying stored metadata # Used to replace an existing upload with another +file+ without modifying stored metadata
# Use this method only to repair/replace an existing upload, or to upload to a Geo secondary node # Use this method only to repair/replace an existing upload, or to upload to a Geo secondary node
# #
# @param [CarrierWave::SanitizedFile] file # @param [CarrierWave::SanitizedFile] file that will replace existing upload
# @return CarrierWave::SanitizedFile # @return CarrierWave::SanitizedFile
def replace_file_without_saving!(file) def replace_file_without_saving!(file)
raise ArgumentError, 'should be a CarrierWave::SanitizedFile' unless file.is_a? CarrierWave::SanitizedFile raise ArgumentError, 'should be a CarrierWave::SanitizedFile' unless file.is_a? CarrierWave::SanitizedFile
......
...@@ -199,13 +199,10 @@ module Gitlab ...@@ -199,13 +199,10 @@ module Gitlab
# Upload file to Object Storage # Upload file to Object Storage
uploader.replace_file_without_saving!(CarrierWave::SanitizedFile.new(temp_file)) uploader.replace_file_without_saving!(CarrierWave::SanitizedFile.new(temp_file))
log_info("Successful downloaded", filename: filename, file_size_bytes: file_size) log_info("Successfully transferred", file_type: file_type, file_id: file_id,
file_size_bytes: file_size)
rescue => e rescue => e
log_error("Error downloading file", error: e, filename: filename, url: url) log_error("Error transferring file", error: e, file_type: file_type, file_id: file_id, url: url)
return failure_result
rescue Errno::EEXIST => e
log_error("Destination file is a directory", error: e, filename: filename)
return failure_result return failure_result
ensure ensure
......
...@@ -42,7 +42,7 @@ describe Geo::UploadRegistry, :geo, :geo_fdw do ...@@ -42,7 +42,7 @@ describe Geo::UploadRegistry, :geo, :geo_fdw do
upload = create(:upload, :with_file) upload = create(:upload, :with_file)
registry = create(:geo_upload_registry, :file, file_id: upload.id) registry = create(:geo_upload_registry, :file, file_id: upload.id)
expect(registry.file).to eq("uploads/-/system/project/avatar/#{upload.id}/avatar.jpg") expect(registry.file).to eq(upload.path)
end end
it 'return "removed" message when the upload no longer exists' do it 'return "removed" message when the upload no longer exists' do
......
...@@ -114,10 +114,22 @@ describe Upload do ...@@ -114,10 +114,22 @@ describe Upload do
expect(uploader.upload).to eq(subject) expect(uploader.upload).to eq(subject)
expect(uploader.mounted_as).to eq(subject.send(:mount_point)) expect(uploader.mounted_as).to eq(subject.send(:mount_point))
expect(uploader.file).to be_nil
end end
end end
describe '#needs_checksum??' do describe '#retrieve_uploader' do
it 'returns a uploader object with current uploader associated with and cache retrieved' do
subject = build(:upload)
uploader = subject.retrieve_uploader
expect(uploader.upload).to eq(subject)
expect(uploader.mounted_as).to eq(subject.send(:mount_point))
expect(uploader.file).not_to be_nil
end
end
describe '#needs_checksum?' do
context 'with local storage' do context 'with local storage' do
it 'returns true when no checksum exists' do it 'returns true when no checksum exists' do
subject = create(:upload, :with_file, checksum: nil) subject = create(:upload, :with_file, checksum: nil)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment