From 7e567d5080a39935413b0e703aefebe29b2b2ba3 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Fri, 2 Jun 2023 17:05:19 +0200 Subject: [PATCH] fix(instructeurs): don't crash when displaying "avis" column --- app/models/procedure_presentation.rb | 5 +++++ spec/models/procedure_presentation_spec.rb | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 194ef1519..bfc6cd1cb 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' }