-
Notifications
You must be signed in to change notification settings - Fork 92
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 #11384 from colinux/no-automatic-en-instruction-wi…
…th-pending-correction ETQ instructeur la clôture auto d'une démarche laisse les dossiers en attente de correction en construction
- Loading branch information
Showing
6 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
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
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
34 changes: 34 additions & 0 deletions
34
app/tasks/maintenance/t20250226_fix_dossiers_en_instruction_with_pending_correction_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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module Maintenance | ||
class T20250226FixDossiersEnInstructionWithPendingCorrectionTask < MaintenanceTasks::Task | ||
# Cette tâche traite les dossiers en instruction avec une correction en attente pour les repasser en construction. | ||
|
||
include RunnableOnDeployConcern | ||
include StatementsHelpersConcern | ||
|
||
attribute :procedure_id, :string | ||
validates :procedure_id, presence: true | ||
|
||
def collection | ||
Procedure.find(procedure_id) | ||
.dossiers | ||
.state_en_instruction | ||
.with_pending_corrections | ||
end | ||
|
||
def process(dossier) | ||
Dossier.transaction do | ||
correction = dossier.pending_correction | ||
dossier.resolve_pending_correction | ||
|
||
dossier.repasser_en_construction!(instructeur: correction.commentaire.instructeur) | ||
|
||
correction.update!(resolved_at: nil) | ||
end | ||
rescue => e | ||
Rails.logger.error("Failed to process dossier #{dossier.id}: #{e.message}") | ||
Sentry.capture_exception(e, dossier: dossier.id) | ||
end | ||
end | ||
end |
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
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
54 changes: 54 additions & 0 deletions
54
...ks/maintenance/t20250226_fix_dossiers_en_instruction_with_pending_correction_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,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
module Maintenance | ||
RSpec.describe T20250226FixDossiersEnInstructionWithPendingCorrectionTask do | ||
let(:instructeur) { create(:instructeur) } | ||
let(:dossier) { create(:dossier, :en_instruction) } | ||
let(:commentaire) { create(:commentaire, dossier:, instructeur:) } | ||
|
||
before do | ||
dossier.flag_as_pending_correction!(commentaire) | ||
dossier.update(state: "en_instruction") | ||
end | ||
|
||
describe "#process" do | ||
subject(:process) { described_class.process(dossier) } | ||
|
||
it "repasse le dossier en construction avec la correction toujours en attente" do | ||
expect(dossier).to be_en_instruction | ||
expect(dossier.corrections.one?(&:pending?)).to be_truthy | ||
process | ||
dossier.reload | ||
expect(dossier).to be_en_construction | ||
expect(dossier.corrections.one?(&:pending?)).to be_truthy | ||
end | ||
|
||
it "does not send any email" do | ||
expect { perform_enqueued_jobs { process } }.not_to change { ActionMailer::Base.deliveries.count } | ||
end | ||
|
||
it "creates operation log" do | ||
expect { process }.to change { DossierOperationLog.count }.by(1) | ||
log = DossierOperationLog.last | ||
expect(log.data["author"]).to eq(DossierOperationLog.serialize_author(instructeur)) | ||
expect(log).to be_repasser_en_construction | ||
end | ||
|
||
context "when something fails during transaction" do | ||
before do | ||
allow(dossier).to receive(:repasser_en_construction!).and_raise("boom") | ||
end | ||
|
||
it "rolls back all changes" do | ||
expect(dossier).to be_en_instruction | ||
process | ||
dossier.reload | ||
expect(dossier).to be_en_instruction | ||
expect(dossier.corrections.one?(&:pending?)).to be_truthy | ||
end | ||
end | ||
end | ||
end | ||
end |