Commit dd634fec authored by Gabriel Mazetto's avatar Gabriel Mazetto

Raises error when migration cannot happen so job is cancelled

parent 0bb65053
module Projects module Projects
module HashedStorage module HashedStorage
AttachmentMigrationError = Class.new(StandardError)
class MigrateAttachmentsService < BaseService class MigrateAttachmentsService < BaseService
attr_reader :logger attr_reader :logger
...@@ -27,7 +29,7 @@ module Projects ...@@ -27,7 +29,7 @@ module Projects
if File.exist?(new_path) if File.exist?(new_path)
logger.error("Cannot migrate attachments from '#{old_path}' to '#{new_path}', target path already exist (PROJECT_ID=#{project.id})") logger.error("Cannot migrate attachments from '#{old_path}' to '#{new_path}', target path already exist (PROJECT_ID=#{project.id})")
return raise AttachmentMigrationError, "Target path '#{new_path}' already exist"
end end
# Create hashed storage base path folder # Create hashed storage base path folder
......
...@@ -49,13 +49,10 @@ describe Projects::HashedStorage::MigrateAttachmentsService do ...@@ -49,13 +49,10 @@ describe Projects::HashedStorage::MigrateAttachmentsService do
FileUtils.mkdir_p(base_path(hashed_storage)) FileUtils.mkdir_p(base_path(hashed_storage))
end end
it 'skips moving the file and goes to next' do it 'raises AttachmentMigrationError' do
expect(FileUtils).not_to receive(:mv).with(base_path(legacy_storage), base_path(hashed_storage)) expect(FileUtils).not_to receive(:mv).with(base_path(legacy_storage), base_path(hashed_storage))
service.execute expect { service.execute }.to raise_error(Projects::HashedStorage::AttachmentMigrationError)
expect(File.exist?(base_path(legacy_storage))).to be_truthy
expect(File.file?(old_path)).to be_truthy
end end
end end
end end
......
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