From b36d1536206fd57c3cdf785321441773048f82c0 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 3 Oct 2018 16:20:27 +0200 Subject: [PATCH] Fix missing sort columns --- app/models/procedure_presentation.rb | 7 ++++++- spec/models/procedure_presentation_spec.rb | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index b7ff11662..b9fccc2d7 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -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 diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 50bfabd3c..3cc555401 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -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