Add DiscardedProceduresDeletionJob job

This commit is contained in:
Paul Chavard 2020-03-26 17:37:55 +01:00
parent da52ec30bd
commit 58c126308c
4 changed files with 17 additions and 3 deletions

View file

@ -0,0 +1,10 @@
class DiscardedProceduresDeletionJob < CronJob
self.cron_expression = "0 7 * * *"
def perform(*args)
Procedure.discarded_expired.find_each do |procedure|
procedure.dossiers.with_discarded.destroy_all
procedure.destroy
end
end
end

View file

@ -212,9 +212,7 @@ class Dossier < ApplicationRecord
with_discarded
.discarded
.state_en_construction
.joins(:procedure)
.where('dossiers.hidden_at < ?', 1.month.ago)
.where(procedures: { hidden_at: nil })
end
scope :brouillon_near_procedure_closing_date, -> do

View file

@ -53,6 +53,12 @@ class Procedure < ApplicationRecord
scope :cloned_from_library, -> { where(cloned_from_library: true) }
scope :declarative, -> { where.not(declarative_with_state: nil) }
scope :discarded_expired, -> do
with_discarded
.discarded
.where('hidden_at < ?', 1.month.ago)
end
scope :for_api, -> {
includes(
:administrateurs,

View file

@ -1248,6 +1248,6 @@ describe Dossier do
end
it { expect(Dossier.discarded_brouillon_expired.count).to eq(2) }
it { expect(Dossier.discarded_en_construction_expired.count).to eq(1) }
it { expect(Dossier.discarded_en_construction_expired.count).to eq(2) }
end
end