Merge pull request #10139 from mfo/US/fix-missing-champs-task
fix(data): apply fix missing champ via task. FV dossiers are poping way too much at helpdesk
This commit is contained in:
commit
aafe6a7bb6
2 changed files with 43 additions and 0 deletions
24
app/tasks/maintenance/fix_missing_champs_task.rb
Normal file
24
app/tasks/maintenance/fix_missing_champs_task.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# bundle exec maintenance_tasks perform Maintenance::FixMissingChampsTask --arguments procedure_ids:id1,id2,id3
|
||||
module Maintenance
|
||||
class FixMissingChampsTask < MaintenanceTasks::Task
|
||||
attribute :procedure_ids, array: true, default: []
|
||||
|
||||
def collection
|
||||
Dossier.joins(:procedure).where(procedure: { id: procedure_ids }).in_batches
|
||||
end
|
||||
|
||||
def process(dossiers)
|
||||
# rubocop:disable Rails/FindEach
|
||||
DossierPreloader.new(dossiers).all.each do |dossier|
|
||||
# rubocop:enable Rails/FindEach
|
||||
maybe_fixable = [dossier, dossier.editing_forks.first].compact.any? { _1.champs.size < _1.revision.types_de_champ.size }
|
||||
if maybe_fixable
|
||||
added_champ_count = DataFixer::DossierChampsMissing.new(dossier:).fix
|
||||
rake_puts "fixed: #{dossier.id}, adding: #{added_champ_count}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
spec/tasks/maintenance/fix_missing_champs_task_spec.rb
Normal file
19
spec/tasks/maintenance/fix_missing_champs_task_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
module Maintenance
|
||||
RSpec.describe FixMissingChampsTask do
|
||||
describe "#process" do
|
||||
subject(:process) { described_class.process(dossiers) }
|
||||
let(:procedure) { create(:procedure, types_de_champ_public:) }
|
||||
let(:types_de_champ_public) { [{ type: :text, libelle: 'l1' }, { type: :text, libelle: 'l2' }] }
|
||||
let(:dossier_1) { create(:dossier, procedure:) }
|
||||
let(:dossiers) { [dossier_1] }
|
||||
it "add missing champs" do
|
||||
dossier_1.champs.last.destroy
|
||||
expect { subject }.to change { dossier_1.champs.count }.by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue