Merge pull request #10125 from demarches-simplifiees/destroy-procedure-without-administrateur-and-without-dossier
Correctif : supprime les démarches sans administrateur ni dossier
This commit is contained in:
commit
94f37b6708
3 changed files with 40 additions and 0 deletions
|
@ -82,6 +82,10 @@ class Administrateur < ApplicationRecord
|
|||
|
||||
next_administrateur = procedure.administrateurs.where.not(id: self.id).first
|
||||
procedure.service.update(administrateur: next_administrateur)
|
||||
|
||||
if (procedure.administrateurs.count == 1 && procedure.dossiers.empty?)
|
||||
procedure.destroy
|
||||
end
|
||||
end
|
||||
|
||||
services.each do |service|
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in a new issue