update_sort double write

This commit is contained in:
simon lehericey 2024-10-07 22:02:43 +02:00
parent a7ebe23504
commit 98c2b7e954
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 30 additions and 5 deletions

View file

@ -147,12 +147,19 @@ class ProcedurePresentation < ApplicationRecord
def update_sort(column_id, order)
h_id = JSON.parse(column_id, symbolize_names: true)
column = procedure.find_column(h_id:)
order = order.presence || opposite_order_for(column.table, column.column)
update!(sort: {
update!(
sort: {
TABLE => column.table,
COLUMN => column.column,
ORDER => order.presence || opposite_order_for(column.table, column.column)
})
ORDER => order
},
sorted_column: {
order:,
id: h_id
}
)
end
def opposite_order_for(table, column)

View file

@ -943,4 +943,22 @@ describe ProcedurePresentation do
end
end
end
describe '#update_sort' do
let(:procedure_presentation) { create(:procedure_presentation, assign_to:) }
subject do
column_id = procedure.find_column(label: 'En construction le').id
procedure_presentation.update_sort(column_id, 'asc')
end
it 'should update sort and order' do
expect(procedure_presentation.sorted_column).to be_nil
subject
expect(procedure_presentation.sorted_column['id']).to eq("column_id" => "self/en_construction_at", "procedure_id" => procedure.id)
expect(procedure_presentation.sorted_column['order']).to eq('asc')
end
end
end