diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 42e47398d..34f194a8d 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -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}") diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 7cabd11a7..319c38b2d 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -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 it’s ok to test only one let(:table) { 'etablissement' }