task: ensure that hidden dossiers are rolled back

This commit is contained in:
Pierre de La Morinerie 2019-06-18 15:06:26 +00:00
parent d71b3ade80
commit d561936863
2 changed files with 17 additions and 1 deletions

View file

@ -141,7 +141,7 @@ class PieceJustificativeToChampPieceJointeMigrationService
# First destroy all the individual champs on dossiers
type_champ.champ.each do |champ|
begin
destroy_champ_pj(champ.dossier.reload, champ)
destroy_champ_pj(Dossier.unscope(where: :hidden_at).find(champ.dossier_id), champ)
rescue => e
rake_puts e
rake_puts "Rolling back of champ #{champ.id} failed. Continuing to roll back…"

View file

@ -265,6 +265,22 @@ describe PieceJustificativeToChampPieceJointeMigrationService do
.not_to change { ActiveStorage::Attachment.count }
end
context 'when some dossiers to roll back are hidden' do
before do
dossier.update_column(:hidden_at, Time.zone.now)
end
it 'does not create champs' do
expect { try_convert(procedure) }
.not_to change { dossier.champs.count }
end
it 'does not change the hidden dossier timestamps' do
try_convert(procedure)
expect(dossier.updated_at).to eq(initial_dossier_timestamps[:updated_at])
end
end
context 'when receiving a Signal interruption (like Ctrl+C)' do
let(:exception) { Interrupt }