From 63225328051daefed272f67a6499a8367c9413c4 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Fri, 15 Mar 2024 16:11:58 +0100 Subject: [PATCH] fix(data): destroy procedure if no administrateur and no dossier --- ...administrateur_and_without_dossier_task.rb | 13 +++++++++++ ...istrateur_and_without_dossier_task_spec.rb | 23 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 app/tasks/maintenance/destroy_procedure_without_administrateur_and_without_dossier_task.rb create mode 100644 spec/tasks/maintenance/destroy_procedure_without_administrateur_and_without_dossier_task_spec.rb diff --git a/app/tasks/maintenance/destroy_procedure_without_administrateur_and_without_dossier_task.rb b/app/tasks/maintenance/destroy_procedure_without_administrateur_and_without_dossier_task.rb new file mode 100644 index 000000000..70860af82 --- /dev/null +++ b/app/tasks/maintenance/destroy_procedure_without_administrateur_and_without_dossier_task.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Maintenance + class DestroyProcedureWithoutAdministrateurAndWithoutDossierTask < MaintenanceTasks::Task + def collection + Procedure.with_discarded.where.missing(:administrateurs, :dossiers) + end + + def process(procedure) + procedure.destroy! + end + end +end diff --git a/spec/tasks/maintenance/destroy_procedure_without_administrateur_and_without_dossier_task_spec.rb b/spec/tasks/maintenance/destroy_procedure_without_administrateur_and_without_dossier_task_spec.rb new file mode 100644 index 000000000..92a390b31 --- /dev/null +++ b/spec/tasks/maintenance/destroy_procedure_without_administrateur_and_without_dossier_task_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "rails_helper" + +module Maintenance + RSpec.describe DestroyProcedureWithoutAdministrateurAndWithoutDossierTask do + describe "#process" do + subject(:process) { described_class.process(procedure) } + let(:procedure) { create(:procedure) } + + before do + administrateur = procedure.administrateurs.first + AdministrateursProcedure.where(administrateur_id: administrateur.id).delete_all + administrateur.destroy + end + + it "destroys procedure" do + subject + expect(Procedure.count).to eq 0 + end + end + end +end