-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11102 from tchak/remove-unused-forks
cleanup(dossier): remove unused forks
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
app/tasks/maintenance/t20241202remove_unused_forks_task.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
23 changes: 23 additions & 0 deletions
23
spec/tasks/maintenance/t20241202remove_unused_forks_task_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |