From 92da86966264f9f2d3a9d175400518d812392e8a Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 28 Nov 2023 15:00:24 +0100 Subject: [PATCH] spec: Dossier.purge_discarded --- spec/models/dossier_purge_spec.rb | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 spec/models/dossier_purge_spec.rb diff --git a/spec/models/dossier_purge_spec.rb b/spec/models/dossier_purge_spec.rb new file mode 100644 index 000000000..8ff12a8c2 --- /dev/null +++ b/spec/models/dossier_purge_spec.rb @@ -0,0 +1,33 @@ +describe Dossier, type: :model do + describe '.purge_discarded' do + it 'discards brouillon, en_construction and termine' do + [ + :en_brouillon_expired_to_delete, + :en_construction_expired_to_delete, + :termine_expired_to_delete + ].each do |scope| + dossier = double(purge_discarded: true) + expect(dossier).to receive(:purge_discarded) + + collection = double(find_each: true) + expect(collection).to receive(:find_each) { |&block| block.call(dossier) } + + expect(Dossier).to receive(scope).and_return(collection) + end + + Dossier.purge_discarded + end + end + + describe '#purge_discarded' do + let(:dossier) { create(:dossier) } + + it 'creates a deleted dossier, purge the dols and then destroy' do + expect(DeletedDossier).to receive(:create_from_dossier) + expect(dossier.dossier_operation_logs).to receive(:purge_discarded) + expect(dossier).to receive(:destroy) + + dossier.purge_discarded + end + end +end