Fix missing sort columns

This commit is contained in:
Frederic Merizen 2018-10-03 16:20:27 +02:00
parent 2e581e3549
commit b36d153620
2 changed files with 8 additions and 1 deletions

View file

@ -1,4 +1,9 @@
class ProcedurePresentation < ApplicationRecord
EXTRA_SORT_COLUMNS = {
'notifications' => Set['notifications'],
'self' => Set['id', 'state']
}
belongs_to :assign_to
delegate :procedure, to: :assign_to
@ -40,6 +45,6 @@ class ProcedurePresentation < ApplicationRecord
private
def valid_sort_column?(procedure, table, column)
DossierFieldService.valid_column?(procedure, table, column) || (table == 'notifications' && column == 'notifications')
DossierFieldService.valid_column?(procedure, table, column) || EXTRA_SORT_COLUMNS[table]&.include?(column)
end
end

View file

@ -37,6 +37,8 @@ describe ProcedurePresentation do
context 'of sort' do
it { expect(build(:procedure_presentation, sort: { "table" => "notifications", "column" => "notifications", "order" => "asc" })).to be_valid }
it { expect(build(:procedure_presentation, sort: { "table" => "self", "column" => "id", "order" => "asc" })).to be_valid }
it { expect(build(:procedure_presentation, sort: { "table" => "self", "column" => "state", "order" => "asc" })).to be_valid }
it { expect(build(:procedure_presentation, sort: { "table" => "user", "column" => "reset_password_token", "order" => "asc" })).to be_invalid }
end