fix: filter with a text instead of a integer does not crash

This commit is contained in:
simon lehericey 2024-11-26 09:38:49 +01:00
parent 99184d3d2b
commit 6516533083
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 8 additions and 0 deletions

View file

@ -90,6 +90,8 @@ class DossierFilterService
dossiers.joins(:corrections).where(corrections: DossierCorrection.pending) dossiers.joins(:corrections).where(corrections: DossierCorrection.pending)
elsif filtered_column.column == "state" && values.include?("en_construction") elsif filtered_column.column == "state" && values.include?("en_construction")
dossiers.where("dossiers.#{column} IN (?)", values).includes(:corrections).where.not(corrections: DossierCorrection.pending) 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 else
dossiers.where("dossiers.#{column} IN (?)", values) dossiers.where("dossiers.#{column} IN (?)", values)
end end

View file

@ -766,5 +766,11 @@ describe DossierFilterService do
end end
end 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
end end