fix(data): normalize invalid Champs::RNAChamp.values in db
This commit is contained in:
parent
abb2fa159c
commit
22e50d4c9e
2 changed files with 38 additions and 0 deletions
19
app/tasks/maintenance/normalize_rna_values_task.rb
Normal file
19
app/tasks/maintenance/normalize_rna_values_task.rb
Normal 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
|
19
spec/tasks/maintenance/normalize_rna_values_task_spec.rb
Normal file
19
spec/tasks/maintenance/normalize_rna_values_task_spec.rb
Normal 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
|
Loading…
Reference in a new issue