From 1c32a30b80bc750c0373f0d6611b5a5153fc499e Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Mon, 14 Oct 2024 15:36:18 +0200 Subject: [PATCH] fix(filters): drop down list filters can have much longer values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Notre infra supporte des urls d'au moins 8000 caractères, probablement plus encore, donc on est large. --- app/models/procedure_presentation.rb | 2 +- .../instructeurs/procedures_controller_spec.rb | 4 ++-- spec/models/procedure_presentation_spec.rb | 12 ++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 828827ecd23..d1fb52cebb1 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -8,7 +8,7 @@ class ProcedurePresentation < ApplicationRecord SLASH = '/' TYPE_DE_CHAMP = 'type_de_champ' - FILTERS_VALUE_MAX_LENGTH = 100 + FILTERS_VALUE_MAX_LENGTH = 4048 # https://www.postgresql.org/docs/current/datatype-numeric.html PG_INTEGER_MAX_VALUE = 2147483647 diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index 1dcb18a3532..c9e1a8894c4 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -906,12 +906,12 @@ def procedure_presentation = instructeur.assign_to.first.procedure_presentation_ subject do column = procedure.find_column(label: "Nom").id - post :add_filter, params: { procedure_id: procedure.id, column:, value: "n" * 110, statut: "a-suivre" } + post :add_filter, params: { procedure_id: procedure.id, column:, value: "n" * 4100, statut: "a-suivre" } end it 'should render the error' do subject - expect(flash.alert[0]).to include("Le filtre Nom est trop long (maximum: 100 caractères)") + expect(flash.alert[0]).to include("Le filtre Nom est trop long (maximum: 4048 caractères)") end end end diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 1a42bb1a26e..a160e0a5ea1 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -42,12 +42,16 @@ end context 'of filters' do - it { expect(build(:procedure_presentation, filters: { "suivis" => [{ table: "user", column: "reset_password_token", "order" => "asc" }] })).to be_invalid } - it { expect(build(:procedure_presentation, filters: { "suivis" => [{ table: "user", column: "email", "value" => "exceedingly long filter value" * 10 }] })).to be_invalid } + it do + expect(build(:procedure_presentation, filters: { "suivis" => [{ table: "user", column: "reset_password_token", "order" => "asc" }] })).to be_invalid + expect(build(:procedure_presentation, filters: { "suivis" => [{ table: "user", column: "email", "value" => "exceedingly long filter value" * 1000 }] })).to be_invalid + end describe 'check_filters_max_integer' do - it { expect(build(:procedure_presentation, filters: { "suivis" => [{ table: "self", column: "id", "value" => ProcedurePresentation::PG_INTEGER_MAX_VALUE.to_s }] })).to be_invalid } - it { expect(build(:procedure_presentation, filters: { "suivis" => [{ table: "self", column: "id", "value" => (ProcedurePresentation::PG_INTEGER_MAX_VALUE - 1).to_s }] })).to be_valid } + it do + expect(build(:procedure_presentation, filters: { "suivis" => [{ table: "self", column: "id", "value" => ProcedurePresentation::PG_INTEGER_MAX_VALUE.to_s }] })).to be_invalid + expect(build(:procedure_presentation, filters: { "suivis" => [{ table: "self", column: "id", "value" => (ProcedurePresentation::PG_INTEGER_MAX_VALUE - 1).to_s }] })).to be_valid + end end end end