fix(instructeurs): don't crash when displaying "avis" column

This commit is contained in:
Colin Darie 2023-06-02 17:05:19 +02:00
parent 5d245fee7d
commit 7e567d5080
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
2 changed files with 22 additions and 0 deletions

View file

@ -163,6 +163,11 @@ class ProcedurePresentation < ApplicationRecord
.order("instructeurs_users.email #{order}")
.pluck(:id)
.uniq
when 'avis'
dossiers.includes(table)
.order("#{self.class.sanitized_column(table, column)} #{order}")
.pluck(:id)
.uniq
when 'self', 'user', 'individual', 'etablissement', 'groupe_instructeur'
(table == 'self' ? dossiers : dossiers.includes(table))
.order("#{self.class.sanitized_column(table, column)} #{order}")

View file

@ -382,6 +382,23 @@ describe ProcedurePresentation do
end
end
context 'for avis table' do
let(:table) { 'avis' }
let(:column) { 'answer' }
let(:order) { 'asc' }
let!(:dossier_yes) { create(:dossier, procedure:) }
let!(:dossier_no) { create(:dossier, procedure:) }
before do
create_list(:avis, 2, dossier: dossier_yes, question_answer: true)
create(:avis, dossier: dossier_no, question_answer: true)
create(:avis, dossier: dossier_no, question_answer: false)
end
it { is_expected.to eq([dossier_yes, dossier_no].map(&:id)) }
end
context 'for other tables' do
# All other columns and tables work the same so its ok to test only one
let(:table) { 'etablissement' }