update_display double write
This commit is contained in:
parent
98c2b7e954
commit
5f6d8e93ca
4 changed files with 35 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:) }
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue