update_display double write

This commit is contained in:
simon lehericey 2024-10-07 22:04:44 +02:00
parent 98c2b7e954
commit 5f6d8e93ca
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
4 changed files with 35 additions and 14 deletions

View file

@ -613,14 +613,6 @@ class Procedure < ApplicationRecord
end
end
def self.default_sort
{
'table' => 'self',
'column' => 'id',
'order' => 'desc'
}
end
def whitelist!
touch(:whitelisted_at)
end

View file

@ -137,10 +137,14 @@ class ProcedurePresentation < ApplicationRecord
h_ids = Array.wrap(column_ids).map { |id| JSON.parse(id, symbolize_names: true) }
columns = h_ids.map { |h_id| procedure.find_column(h_id:) }
update!(displayed_fields: columns)
update!(
displayed_fields: columns,
displayed_columns: columns.map(&:h_id)
)
if !sort_to_column_id(sort).in?(column_ids)
update!(sort: Procedure.default_sort)
default_column_id = procedure.dossier_id_column.id
update_sort(default_column_id, "desc")
end
end

View file

@ -944,6 +944,35 @@ describe ProcedurePresentation do
end
end
describe '#update_displayed_fields' do
let(:procedure_presentation) do
create(:procedure_presentation, assign_to:).tap do |pp|
pp.update_sort(procedure.find_column(label: 'Demandeur').id, 'desc')
end
end
subject do
procedure_presentation.update_displayed_fields([
procedure.find_column(label: 'En construction le').id,
procedure.find_column(label: 'Mis à jour le').id
])
end
it 'should update displayed_fields' do
expect(procedure_presentation.displayed_columns).to eq([])
subject
expect(procedure_presentation.displayed_columns).to eq([
{ "column_id" => "self/en_construction_at", "procedure_id" => procedure.id },
{ "column_id" => "self/updated_at", "procedure_id" => procedure.id }
])
expect(procedure_presentation.sorted_column['id']).to eq("column_id" => "self/id", "procedure_id" => procedure.id)
expect(procedure_presentation.sorted_column['order']).to eq('desc')
end
end
describe '#update_sort' do
let(:procedure_presentation) { create(:procedure_presentation, assign_to:) }

View file

@ -1450,10 +1450,6 @@ describe Procedure do
end
end
describe ".default_sort" do
it { expect(Procedure.default_sort).to eq({ "table" => "self", "column" => "id", "order" => "desc" }) }
end
describe "#organisation_name" do
subject { procedure.organisation_name }
context 'when the procedure has a service (and no organization)' do