-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update procedure_presentation, export and export_template to reserial…
…ize column address (->, .) et departement -> department
- Loading branch information
Showing
4 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
app/tasks/maintenance/migrate_export_address_and_linked_columns_task.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
19 changes: 19 additions & 0 deletions
19
app/tasks/maintenance/migrate_export_template_address_and_linked_columns_task.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
28 changes: 28 additions & 0 deletions
28
app/tasks/maintenance/migrate_procedure_presentation_address_and_linked_columns_task.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
101 changes: 101 additions & 0 deletions
101
.../tasks/maintenance/migrate_procedure_presentation_address_and_linked_columns_task_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |