From 737c1a9faad42c5c8b7710dea0950734a3756d66 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Mon, 2 Dec 2024 10:56:50 +0100 Subject: [PATCH] cleanup(dossier): remove unused forks --- .../t20241202remove_unused_forks_task.rb | 18 +++++++++++++++ .../t20241202remove_unused_forks_task_spec.rb | 23 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 app/tasks/maintenance/t20241202remove_unused_forks_task.rb create mode 100644 spec/tasks/maintenance/t20241202remove_unused_forks_task_spec.rb diff --git a/app/tasks/maintenance/t20241202remove_unused_forks_task.rb b/app/tasks/maintenance/t20241202remove_unused_forks_task.rb new file mode 100644 index 000000000..ec22aad08 --- /dev/null +++ b/app/tasks/maintenance/t20241202remove_unused_forks_task.rb @@ -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 diff --git a/spec/tasks/maintenance/t20241202remove_unused_forks_task_spec.rb b/spec/tasks/maintenance/t20241202remove_unused_forks_task_spec.rb new file mode 100644 index 000000000..b70e0365e --- /dev/null +++ b/spec/tasks/maintenance/t20241202remove_unused_forks_task_spec.rb @@ -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