feat(dossier_purge): when the dols are purged, only keep supprimer dol but destroy its data
Note, the only remaining data are dossier_id, automatic_operation, digest and bill_id, created_at
This commit is contained in:
parent
92da869662
commit
28b338452a
2 changed files with 90 additions and 1 deletions
|
@ -41,7 +41,9 @@ class DossierOperationLog < ApplicationRecord
|
|||
|
||||
def self.purge_discarded
|
||||
not_deletion.destroy_all
|
||||
with_data.each(&:move_to_cold_storage!)
|
||||
|
||||
supprimer.map { _1.serialized.purge_later }
|
||||
supprimer.update_all(data: nil)
|
||||
end
|
||||
|
||||
def self.create_and_serialize(params)
|
||||
|
|
87
spec/models/dossier_operation_log_spec.rb
Normal file
87
spec/models/dossier_operation_log_spec.rb
Normal file
|
@ -0,0 +1,87 @@
|
|||
describe DossierOperationLog, type: :model do
|
||||
describe '.purge_discarded' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let!(:witness_dossier) do
|
||||
d = create(:dossier)
|
||||
|
||||
DossierOperationLog.create_and_serialize(
|
||||
dossier: d,
|
||||
operation: DossierOperationLog.operations[:passer_en_instruction],
|
||||
author: instructeur
|
||||
)
|
||||
|
||||
DossierOperationLog.create_and_serialize(
|
||||
dossier: d,
|
||||
operation: DossierOperationLog.operations[:supprimer],
|
||||
author: instructeur
|
||||
)
|
||||
|
||||
d
|
||||
end
|
||||
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
|
||||
def dols = dossier.dossier_operation_logs.reload
|
||||
def supprimer_dol = dols.find_by(operation: 'supprimer')
|
||||
def witness_dols = witness_dossier.dossier_operation_logs.reload
|
||||
def witness_supprimer_dol = witness_dols.find_by(operation: 'supprimer')
|
||||
|
||||
it 'purges all operations but supprimer' do
|
||||
DossierOperationLog.create_and_serialize(
|
||||
dossier:,
|
||||
operation: DossierOperationLog.operations[:passer_en_instruction],
|
||||
author: instructeur
|
||||
)
|
||||
|
||||
DossierOperationLog.create_and_serialize(
|
||||
dossier:,
|
||||
operation: DossierOperationLog.operations[:supprimer],
|
||||
author: instructeur
|
||||
)
|
||||
|
||||
expect(dols.count).to eq(2)
|
||||
|
||||
dols.purge_discarded
|
||||
|
||||
expect(dols.map(&:operation)).to match_array('supprimer')
|
||||
expect(witness_dols.map(&:operation)).to match_array(['passer_en_instruction', 'supprimer'])
|
||||
end
|
||||
|
||||
it 'destroys the serialized json from supprimer dol' do
|
||||
DossierOperationLog.create_and_serialize(
|
||||
dossier:,
|
||||
operation: DossierOperationLog.operations[:supprimer],
|
||||
author: instructeur
|
||||
)
|
||||
|
||||
# serialize data attribute to json and store it to cold storage
|
||||
perform_enqueued_jobs do
|
||||
dols.each(&:move_to_cold_storage!)
|
||||
witness_dols.each(&:move_to_cold_storage!)
|
||||
end
|
||||
|
||||
expect(supprimer_dol.serialized.attached?).to be true
|
||||
|
||||
perform_enqueued_jobs { dols.purge_discarded }
|
||||
|
||||
expect(supprimer_dol.serialized.attached?).to be false
|
||||
expect(witness_supprimer_dol.serialized.attached?).to be true
|
||||
end
|
||||
|
||||
it 'nillifies the data attribut of not net seriaized supprimer dol' do
|
||||
DossierOperationLog.create_and_serialize(
|
||||
dossier:,
|
||||
operation: DossierOperationLog.operations[:supprimer],
|
||||
author: instructeur
|
||||
)
|
||||
|
||||
expect(supprimer_dol.data).to be_present
|
||||
|
||||
dols.purge_discarded
|
||||
|
||||
expect(supprimer_dol.serialized.attached?).to be false
|
||||
expect(supprimer_dol.data).to be_nil
|
||||
expect(witness_supprimer_dol.data).to be_present
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue