Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETQ instructeur je peux filtrer un champ "choix simple" avec un long libellé d'option #10930

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/procedure_presentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/instructeurs/procedures_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 8 additions & 4 deletions spec/models/procedure_presentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading