From 6a5a82ce06bb9d6f31da10cca7c619c004f01448 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 3 Oct 2022 15:18:46 +0200 Subject: [PATCH] fix(instructeur dashboard): dossiers filtered on multiple states --- app/models/procedure_presentation.rb | 2 +- spec/models/procedure_presentation_spec.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 7b5ac387f..82a26f1ae 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -182,7 +182,7 @@ class ProcedurePresentation < ApplicationRecord dossiers.filter_by_datetimes(column, dates) else - dossiers.where("dossiers.#{column} = ?", values) + dossiers.where("dossiers.#{column} IN (?)", values) end when TYPE_DE_CHAMP dossiers.with_type_de_champ(column) diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 213358568..361438c07 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -487,6 +487,23 @@ describe ProcedurePresentation do is_expected.to contain_exactly(kept_dossier.id, other_kept_dossier.id) end end + + context 'with multiple state filters' do + let(:filter) do + [ + { 'table' => 'self', 'column' => 'state', 'value' => 'en_construction' }, + { 'table' => 'self', 'column' => 'state', 'value' => 'en_instruction' } + ] + end + + let!(:kept_dossier) { create(:dossier, :en_construction, procedure: procedure) } + let!(:other_kept_dossier) { create(:dossier, :en_instruction, procedure: procedure) } + let!(:discarded_dossier) { create(:dossier, :accepte, procedure: procedure) } + + it 'returns every dossier that matches any of the search criteria for a given column' do + is_expected.to contain_exactly(kept_dossier.id, other_kept_dossier.id) + end + end end context 'for type_de_champ table' do