diff --git a/app/controllers/new_gestionnaire/procedures_controller.rb b/app/controllers/new_gestionnaire/procedures_controller.rb index ac9ef73f1..377b04208 100644 --- a/app/controllers/new_gestionnaire/procedures_controller.rb +++ b/app/controllers/new_gestionnaire/procedures_controller.rb @@ -132,7 +132,7 @@ module NewGestionnaire 'table' => table, 'column' => column, 'order' => order - }.to_json + } procedure_presentation.update(sort: sort) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index f83227269..2f2c10855 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -307,7 +307,7 @@ class Procedure < ApplicationRecord 'table' => 'self', 'column' => 'id', 'order' => 'desc' - }.to_json + } end def whitelist! diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 7f53fc516..f1c701213 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -1,10 +1,6 @@ class ProcedurePresentation < ApplicationRecord belongs_to :assign_to - def sort - JSON.parse(read_attribute(:sort)) - end - def filters JSON.parse(read_attribute(:filters)) end diff --git a/lib/tasks/2018_09_20_procedure_presentation_jsonb.rake b/lib/tasks/2018_09_20_procedure_presentation_jsonb.rake index 01a78a327..114b504c6 100644 --- a/lib/tasks/2018_09_20_procedure_presentation_jsonb.rake +++ b/lib/tasks/2018_09_20_procedure_presentation_jsonb.rake @@ -2,7 +2,8 @@ namespace :'2018_09_20_procedure_presentation_jsonb' do task run: :environment do ProcedurePresentation.update_all( <<~SQL - displayed_fields = ('[' || ARRAY_TO_STRING(old_displayed_fields, ',') || ']')::JSONB + displayed_fields = ('[' || ARRAY_TO_STRING(old_displayed_fields, ',') || ']')::JSONB, + sort = (sort #>> '{}')::jsonb SQL ) end diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 9e69ed408..e3a0072c4 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -7,7 +7,7 @@ describe ProcedurePresentation do { "label" => "test1", "table" => "user" }, { "label" => "test2", "table" => "champs" } ], - sort: { "table" => "user","column" => "email","order" => "asc" }.to_json, + sort: { "table" => "user","column" => "email","order" => "asc" }, filters: { "a-suivre" => [], "suivis" => [{ "label" => "label1", "table" => "table1", "column" => "column1" }] }.to_json ).id } diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 43ae0c653..d41f2413a 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -690,7 +690,7 @@ describe Procedure do end describe ".default_sort" do - it { expect(Procedure.default_sort).to eq("{\"table\":\"self\",\"column\":\"id\",\"order\":\"desc\"}") } + it { expect(Procedure.default_sort).to eq({ "table" => "self", "column" => "id", "order" => "desc" }) } end describe "#export_filename" do