Merge pull request #11102 from tchak/remove-unused-forks

cleanup(dossier): remove unused forks
This commit is contained in:
Paul Chavard 2024-12-02 10:33:16 +00:00 committed by GitHub
commit 9be0d58ac3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,18 @@
# frozen_string_literal: true
module Maintenance
class T20241202removeUnusedForksTask < MaintenanceTasks::Task
# Documentation: Cette tâche supprime les forks laissés après le passage en instruction
include RunnableOnDeployConcern
include StatementsHelpersConcern
def collection
Dossier.joins(:editing_fork_origin).where.not(editing_fork_origin: { state: 'en_construction' })
end
def process(dossier)
dossier.destroy!
end
end
end

View file

@ -0,0 +1,23 @@
# frozen_string_literal: true
require "rails_helper"
module Maintenance
RSpec.describe T20241202removeUnusedForksTask do
describe "#process" do
subject(:collection) { described_class.collection }
let(:procedure) { create(:procedure) }
let(:dossier1) { create(:dossier, :en_construction, procedure:) }
let(:dossier2) { create(:dossier, :en_instruction, procedure:) }
let(:dossier3) { create(:dossier, :accepte, procedure:) }
before do
dossier1.owner_editing_fork
dossier2.owner_editing_fork
dossier3.owner_editing_fork
end
it { is_expected.to match_array([dossier2.owner_editing_fork, dossier3.owner_editing_fork]) }
end
end
end