Merge pull request #11086 from demarches-simplifiees/fix_crashing_filtering

ETQ Instructeur, je n'ai plus de crash lorsque je filtre une colonne numérique avec un texte
This commit is contained in:
LeSim 2024-11-26 12:29:51 +00:00 committed by GitHub
commit 7932085976
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View file

@ -90,6 +90,8 @@ class DossierFilterService
dossiers.joins(:corrections).where(corrections: DossierCorrection.pending)
elsif filtered_column.column == "state" && values.include?("en_construction")
dossiers.where("dossiers.#{column} IN (?)", values).includes(:corrections).where.not(corrections: DossierCorrection.pending)
elsif filtered_column.type == :integer
dossiers.where("dossiers.#{column} IN (?)", values.filter_map { Integer(_1) rescue nil })
else
dossiers.where("dossiers.#{column} IN (?)", values)
end

View file

@ -766,5 +766,11 @@ describe DossierFilterService do
end
end
end
context 'with a buggy filter, for instance a text in a integer column' do
let(:filter) { ['Nº dossier', 'buggy'] }
it { is_expected.to be_empty }
end
end
end