update_sort double write
This commit is contained in:
parent
a7ebe23504
commit
98c2b7e954
2 changed files with 30 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue