fix(data): normalize invalid Champs::RNAChamp.values in db

This commit is contained in:
mfo 2024-08-21 18:00:01 +02:00
parent abb2fa159c
commit 22e50d4c9e
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
2 changed files with 38 additions and 0 deletions

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
module Maintenance
class NormalizeRNAValuesTask < MaintenanceTasks::Task
def collection
Champs::RNAChamp.where.not(value: nil)
end
def process(element)
if /\s/.match?(element.value)
element.update_column(:value, element.value.gsub(/\s+/, ''))
end
end
def count
# to costly
end
end
end

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
require "rails_helper"
module Maintenance
RSpec.describe NormalizeRNAValuesTask do
describe "#process" do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :rna }]) }
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
let(:element) { dossier.champs.first }
subject(:process) { described_class.process(element) }
let(:error_value) { "999 0 999" }
it "removes extra spaces" do
element.update_column(:value, error_value)
expect { subject }.to change { element.reload.value }.from(error_value).to("9990999")
end
end
end
end