tasks: don't abort rollback when a dossier fails
Instead print a warning, and continue rolling back the other dossiers.
This commit is contained in:
parent
91393be13c
commit
f8dda3ae45
2 changed files with 29 additions and 1 deletions
|
@ -139,7 +139,14 @@ class PieceJustificativeToChampPieceJointeMigrationService
|
|||
def rollback_migration!(types_de_champ_pj)
|
||||
types_de_champ_pj.each do |type_champ|
|
||||
# First destroy all the individual champs on dossiers
|
||||
type_champ.champ.each { |c| destroy_champ_pj(c.dossier.reload, c) }
|
||||
type_champ.champ.each do |champ|
|
||||
begin
|
||||
destroy_champ_pj(champ.dossier.reload, champ)
|
||||
rescue => e
|
||||
rake_puts e
|
||||
rake_puts "Rolling back of champ #{champ.id} failed. Continuing to roll back…"
|
||||
end
|
||||
end
|
||||
# Now we can destroy the type de champ itself,
|
||||
# without cascading the timestamp update on all attached dossiers.
|
||||
type_champ.reload.destroy
|
||||
|
|
|
@ -276,5 +276,26 @@ describe PieceJustificativeToChampPieceJointeMigrationService do
|
|||
expect { try_convert(procedure) }.not_to change { dossier.champs.count }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when rolling back a dossier fails' do
|
||||
before do
|
||||
allow(service).to receive(:destroy_champ_pj)
|
||||
.with(having_attributes(id: dossier.id), anything)
|
||||
.and_raise(StandardError)
|
||||
allow(service).to receive(:destroy_champ_pj)
|
||||
.with(any_args)
|
||||
.and_call_original
|
||||
end
|
||||
|
||||
it 'continues to roll back the other dossiers' do
|
||||
expect { try_convert(procedure) }
|
||||
.not_to change { failing_dossier.champs.count }
|
||||
end
|
||||
|
||||
it 'does not creates types de champ on the procedure' do
|
||||
expect { try_convert(procedure) }
|
||||
.not_to change { procedure.types_de_champ.count }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue