Merge pull request #2752 from betagouv/frederic/fix_missing_sort_columns

Fix missing sort columns
This commit is contained in:
Frederic Merizen 2018-10-03 17:28:09 +02:00 committed by GitHub
commit fa359a5ea8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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