Commit ced802df authored by Valery Sizov's avatar Valery Sizov Committed by Gabriel Mazetto

Geo: Use relative path for delete events in SSF

parent 4c93874c
......@@ -66,10 +66,18 @@ module Geo
::Geo::FileRegistryRemovalService.new(
replicable_name,
model_record_id,
event_data[:blob_path]
removed_blob_path(event_data[:uploader_class], event_data[:blob_path])
).execute
end
def removed_blob_path(uploader_class, path)
return unless path.present?
# Backward compatibility check. Remove in 15.x
return path if uploader_class.nil?
File.join(uploader_class.constantize.root, path)
end
# Returns a checksum of the file
#
# @return [String] SHA256 hash of the carrierwave file
......@@ -97,7 +105,7 @@ module Geo
end
def deleted_params
{ model_record_id: model_record.id, blob_path: blob_path }
{ model_record_id: model_record.id, uploader_class: carrierwave_uploader.class.to_s, blob_path: carrierwave_uploader.relative_path }
end
# Return whether it's capable of generating a checksum of itself
......
......@@ -74,7 +74,14 @@ RSpec.shared_examples 'a blob replicator' do
end.to change { ::Geo::Event.count }.by(1)
expect(::Geo::Event.last.attributes).to include(
"replicable_name" => replicator.replicable_name, "event_name" => "deleted", "payload" => { "model_record_id" => replicator.model_record.id, "blob_path" => replicator.blob_path })
"replicable_name" => replicator.replicable_name,
"event_name" => "deleted",
"payload" => {
"model_record_id" => replicator.model_record.id,
"uploader_class" => replicator.carrierwave_uploader.class.to_s,
"blob_path" => replicator.carrierwave_uploader.relative_path.to_s
}
)
end
context 'when replication feature flag is disabled' do
......@@ -120,8 +127,9 @@ RSpec.shared_examples 'a blob replicator' do
end
let!(:model_record_id) { replicator.model_record_id }
let!(:blob_path) { replicator.blob_path }
let!(:deleted_params) { { model_record_id: model_record_id, blob_path: blob_path } }
let!(:blob_path) { replicator.carrierwave_uploader.relative_path.to_s }
let!(:uploader_class) { replicator.carrierwave_uploader.class.to_s }
let!(:deleted_params) { { model_record_id: model_record_id, uploader_class: uploader_class, blob_path: blob_path } }
context 'when model_record was deleted from the DB and the replicator only has its ID' do
before do
......@@ -138,12 +146,28 @@ RSpec.shared_examples 'a blob replicator' do
it 'invokes Geo::FileRegistryRemovalService' do
service = double(:service)
secondary_blob_path = File.join(uploader_class.constantize.root, blob_path)
expect(service).to receive(:execute)
expect(::Geo::FileRegistryRemovalService)
.to receive(:new).with(secondary_side_replicator.replicable_name, model_record_id, blob_path).and_return(service)
.to receive(:new).with(secondary_side_replicator.replicable_name, model_record_id, secondary_blob_path).and_return(service)
secondary_side_replicator.consume(:deleted, **deleted_params)
end
context 'backward compatibility' do
let!(:deprecated_deleted_params) { { model_record_id: model_record_id, blob_path: blob_path } }
it 'invokes Geo::FileRegistryRemovalService when delete event is in deprecated format' do
service = double(:service)
expect(service).to receive(:execute)
expect(::Geo::FileRegistryRemovalService)
.to receive(:new).with(secondary_side_replicator.replicable_name, model_record_id, blob_path).and_return(service)
secondary_side_replicator.consume(:deleted, **deprecated_deleted_params)
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