Merge pull request #5809 from tchak/fix-stable-filters-migration
Fix stable filters migration
This commit is contained in:
commit
302aee0912
2 changed files with 74 additions and 8 deletions
|
@ -8,30 +8,36 @@ namespace :after_party do
|
|||
procedure_presentations.find_each do |procedure_presentation|
|
||||
filters = procedure_presentation.filters
|
||||
sort = procedure_presentation.sort
|
||||
displayed_fields = procedure_presentation.displayed_fields
|
||||
|
||||
['tous', 'suivis', 'traites', 'a-suivre', 'archives'].each do |statut|
|
||||
filters[statut] = filters[statut].map do |filter|
|
||||
table, column, value = filter.values_at('table', 'column', 'value')
|
||||
table, column = filter.values_at('table', 'column')
|
||||
if table && (table == 'type_de_champ' || table == 'type_de_champ_private')
|
||||
type_de_champ = TypeDeChamp.find_by(id: column)
|
||||
if type_de_champ
|
||||
column = type_de_champ.stable_id
|
||||
end
|
||||
filter['column'] = type_de_champ&.stable_id&.to_s
|
||||
end
|
||||
[table, column, value]
|
||||
filter
|
||||
end
|
||||
end
|
||||
|
||||
table, column = sort.values_at('table', 'column')
|
||||
if table && (table == 'type_de_champ' || table == 'type_de_champ_private')
|
||||
type_de_champ = TypeDeChamp.find_by(id: column)
|
||||
if type_de_champ
|
||||
sort['column'] = type_de_champ.stable_id
|
||||
sort['column'] = type_de_champ&.stable_id&.to_s
|
||||
end
|
||||
|
||||
displayed_fields = displayed_fields.map do |displayed_field|
|
||||
table, column = displayed_field.values_at('table', 'column')
|
||||
if table && (table == 'type_de_champ' || table == 'type_de_champ_private')
|
||||
type_de_champ = TypeDeChamp.find_by(id: column)
|
||||
displayed_field['column'] = type_de_champ&.stable_id&.to_s
|
||||
end
|
||||
displayed_field
|
||||
end
|
||||
|
||||
filters['migrated'] = true
|
||||
procedure_presentation.update_columns(filters: filters, sort: sort)
|
||||
procedure_presentation.update_columns(filters: filters, sort: sort, displayed_fields: displayed_fields)
|
||||
progress.inc
|
||||
end
|
||||
progress.finish
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
describe '20201001161931_migrate_filters_to_use_stable_id' do
|
||||
let(:rake_task) { Rake::Task['after_party:migrate_filters_to_use_stable_id'] }
|
||||
|
||||
let(:procedure) { create(:procedure, :with_instructeur, :with_type_de_champ) }
|
||||
let(:type_de_champ) { procedure.types_de_champ.first }
|
||||
let(:sort) do
|
||||
{
|
||||
"table" => "type_de_champ",
|
||||
"column" => type_de_champ.id.to_s,
|
||||
"order" => "asc"
|
||||
}
|
||||
end
|
||||
let(:filters) do
|
||||
{
|
||||
'tous' => [
|
||||
{
|
||||
"label" => "test",
|
||||
"table" => "type_de_champ",
|
||||
"column" => type_de_champ.id.to_s,
|
||||
"value" => "test"
|
||||
}
|
||||
],
|
||||
'suivis' => [],
|
||||
'traites' => [],
|
||||
'a-suivre' => [],
|
||||
'archives' => []
|
||||
}
|
||||
end
|
||||
let(:displayed_fields) do
|
||||
[
|
||||
{
|
||||
"label" => "test",
|
||||
"table" => "type_de_champ",
|
||||
"column" => type_de_champ.id.to_s
|
||||
}
|
||||
]
|
||||
end
|
||||
let!(:procedure_presentation) do
|
||||
type_de_champ.update_column(:stable_id, 13)
|
||||
procedure_presentation = create(:procedure_presentation, procedure: procedure, assign_to: procedure.groupe_instructeurs.first.assign_tos.first)
|
||||
procedure_presentation.update_columns(sort: sort, filters: filters, displayed_fields: displayed_fields)
|
||||
procedure_presentation
|
||||
end
|
||||
|
||||
before do
|
||||
rake_task.invoke
|
||||
procedure_presentation.reload
|
||||
end
|
||||
|
||||
after { rake_task.reenable }
|
||||
|
||||
context "should migrate procedure_presentation" do
|
||||
it "columns are updated" do
|
||||
expect(procedure_presentation.sort['column']).to eq(type_de_champ.stable_id.to_s)
|
||||
expect(procedure_presentation.filters['tous'][0]['column']).to eq(type_de_champ.stable_id.to_s)
|
||||
expect(procedure_presentation.displayed_fields[0]['column']).to eq(type_de_champ.stable_id.to_s)
|
||||
expect(procedure_presentation.filters['migrated']).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue