Merge pull request #10729 from mfo/US/fix-errored-data
ETQ usager, je souhaite que me dossier soit debloqué
This commit is contained in:
commit
46547cb2cd
2 changed files with 51 additions and 0 deletions
|
@ -0,0 +1,24 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Maintenance
|
||||||
|
class RescueDossierWithInvalidRepetitionTask < MaintenanceTasks::Task
|
||||||
|
INVALID_RELEASE_DATETIME = DateTime.new(2024, 8, 30, 12)
|
||||||
|
def collection
|
||||||
|
Dossier.where("last_champ_updated_at > ?", INVALID_RELEASE_DATETIME).pluck(:id) # heure de l'incident
|
||||||
|
end
|
||||||
|
|
||||||
|
def process(dossier_id)
|
||||||
|
Dossier.find(dossier_id)
|
||||||
|
.champs
|
||||||
|
.filter { _1.row_id.present? && _1.parent_id.blank? }
|
||||||
|
.each(&:destroy!)
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
# some dossier had already been destroyed
|
||||||
|
end
|
||||||
|
|
||||||
|
def count
|
||||||
|
# Optionally, define the number of rows that will be iterated over
|
||||||
|
# This is used to track the task's progress
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,27 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
module Maintenance
|
||||||
|
RSpec.describe RescueDossierWithInvalidRepetitionTask do
|
||||||
|
describe "#process" do
|
||||||
|
let(:procedure) { create(:procedure, types_de_champ_public:) }
|
||||||
|
let(:types_de_champ_public) do
|
||||||
|
[
|
||||||
|
{ type: :repetition, children: [{ type: :text, mandatory: true }] },
|
||||||
|
{ type: :checkbox }
|
||||||
|
]
|
||||||
|
end
|
||||||
|
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
|
||||||
|
let(:invalid_champ) { dossier.champs.find(&:checkbox?) }
|
||||||
|
|
||||||
|
# reproduce bad data
|
||||||
|
before { invalid_champ.update!(row_id: dossier.champs[1].row_id) }
|
||||||
|
|
||||||
|
it "dissociate champ having a row_id without a parent_id" do
|
||||||
|
expect { described_class.process(dossier) }
|
||||||
|
.to change { Champ.exists?(invalid_champ.id) }.from(true).to(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue