Skip to content

Commit

Permalink
update procedure_presentation, export and export_template to reserial…
Browse files Browse the repository at this point in the history
…ize column address (->, .) et departement -> department
  • Loading branch information
LeSim committed Jan 14, 2025
1 parent c366d9b commit d3c99d0
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Maintenance
class MigrateDepartmentAndLinkedDropDownColumnsTask < MaintenanceTasks::Task
include RunnableOnDeployConcern

def collection
Export.all
end

def process(export)
# by using the `will_change!` method, we ensure that the column will be saved
# and thus the address and linked columns id will be migrated to the new format
export.filtered_columns_will_change!
export.sorted_column_will_change!

export.save(validate: false)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Maintenance
class MigrateDepartmentAndLinkedDropDownColumnsTask < MaintenanceTasks::Task
include RunnableOnDeployConcern

def collection
ExportTemplate.all
end

def process(export_template)
# by using the `will_change!` method, we ensure that the column will be saved
# and thus the address and linked columns id will be migrated to the new format
export_template.exported_columns_will_change!

export_template.save(validate: false)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Maintenance
class MigrateProcedurePresentationAddressAndLinkedColumnsTask < MaintenanceTasks::Task
include RunnableOnDeployConcern

def collection
ProcedurePresentation.all
end

def process(procedure_presentation)
# by using the `will_change!` method, we ensure that the column will be saved
# and thus the address and linked columns id will be migrated to the new format
procedure_presentation.displayed_columns_will_change!
procedure_presentation.sorted_column_will_change!
procedure_presentation.a_suivre_filters_will_change!
procedure_presentation.suivis_filters_will_change!
procedure_presentation.traites_filters_will_change!
procedure_presentation.tous_filters_will_change!
procedure_presentation.supprimes_filters_will_change!
procedure_presentation.supprimes_recemment_filters_will_change!
procedure_presentation.expirant_filters_will_change!
procedure_presentation.archives_filters_will_change!

procedure_presentation.save(validate: false)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# frozen_string_literal: true

require "rails_helper"

module Maintenance
RSpec.describe MigrateProcedurePresentationAddressAndLinkedColumnsTask do
def displayed_column_ids
raw = ProcedurePresentation
.connection
.select_value('SELECT array_to_json(displayed_columns) from procedure_presentations')

JSON.parse(raw).map { _1['column_id'] }
end

def a_suivre_column_id
raw = ProcedurePresentation
.connection
.select_value('SELECT array_to_json(a_suivre_filters) from procedure_presentations')
.then { JSON.parse(_1).first }

raw['id']['column_id']
end

describe "#process" do
subject(:process) { described_class.process(ProcedurePresentation.find(procedure_presentation.id)) }

let(:instructeur) { create(:instructeur) }
let(:procedure_presentation) do
groupe_instructeur = procedure.defaut_groupe_instructeur
assign_to = create(:assign_to, instructeur:, groupe_instructeur:)
assign_to.procedure_presentation_or_default_and_errors.first
end

describe "#old_linked_drop_down?" do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :linked_drop_down_list, libelle: 'linked' }]) }

let(:old_syntaxed_columns) do
procedure.columns.filter { _1.label =~ /linked/ }.map do |column|
def column.h_id
original_h_id = super()
original_h_id[:column_id] = original_h_id[:column_id].gsub('.', '->')
original_h_id
end

column
end
end

before do
procedure_presentation.update(displayed_columns: old_syntaxed_columns)
procedure_presentation.update(a_suivre_filters: [FilteredColumn.new(column: old_syntaxed_columns.first, filter: 'filter')])

# destroy the columns cache
Current.procedure_columns = nil
end

it do
# ensure old syntax is present in db
expect(displayed_column_ids.any? { _1.include?('->') }).to be(true)
expect(a_suivre_column_id).to include('->')

process

expect(displayed_column_ids.any? { _1.include?('->') }).to be(false)
expect(a_suivre_column_id).not_to include('->')
end
end

describe "#department_columns" do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :address, libelle: 'address' }]) }
let(:old_department) do
department_column = procedure.columns.filter { _1.id =~ /\$.department/ }.first

def department_column.h_id
original_h_id = super()
original_h_id[:column_id] = original_h_id[:column_id].gsub('department', 'departement')
original_h_id
end

department_column
end

before do
procedure_presentation.update(displayed_columns: [old_department])

# destroy the columns cache
Current.procedure_columns = nil
end

it do
# ensure old syntax is present in db
expect(displayed_column_ids.any? { _1.include?('departement') }).to be(true)

process

expect(displayed_column_ids.any? { _1.include?('departement') }).to be(false)
end
end
end
end
end

0 comments on commit d3c99d0

Please sign in to comment.