Merge pull request #10107 from demarches-simplifiees/fix-duree-conservation-data

fix(data): update procedure with duree_conservation greater than max_duree
This commit is contained in:
Eric Leroy-Terquem 2024-03-13 14:36:09 +00:00 committed by GitHub
commit 7ab8345b39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,20 @@
# frozen_string_literal: true
module Maintenance
class FixDureeConservationGreaterThanMaxDureeConservationTask < MaintenanceTasks::Task
def collection
Procedure.where('duree_conservation_dossiers_dans_ds > max_duree_conservation_dossiers_dans_ds')
end
def process(element)
max_duree = element.max_duree_conservation_dossiers_dans_ds
element.update!(duree_conservation_dossiers_dans_ds: max_duree)
end
def count
# Optionally, define the number of rows that will be iterated over
# This is used to track the task's progress
collection.count
end
end
end

View file

@ -0,0 +1,25 @@
# frozen_string_literal: true
require "rails_helper"
module Maintenance
RSpec.describe FixDureeConservationGreaterThanMaxDureeConservationTask do
describe "#process" do
subject(:process) do
described_class.process(procedure)
end
let(:procedure) { create(:procedure, :published) }
before { procedure.update_column(:duree_conservation_dossiers_dans_ds, 60) }
it 'fixes invalid procedure' do
expect(procedure.duree_conservation_dossiers_dans_ds).to eq 60
expect(procedure).to be_invalid
subject
expect(procedure.duree_conservation_dossiers_dans_ds).to eq 36
expect(procedure).to be_valid
end
end
end
end