fix(data): destroy procedure if no administrateur and no dossier
This commit is contained in:
parent
eae149f49d
commit
6322532805
2 changed files with 36 additions and 0 deletions
|
@ -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