fix(data): destroy procedure if no administrateur and no dossier

This commit is contained in:
Eric Leroy-Terquem 2024-03-15 16:11:58 +01:00
parent eae149f49d
commit 6322532805
2 changed files with 36 additions and 0 deletions

View file

@ -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

View file

@ -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