Merge pull request #10025 from colinux/fix-filter-too-long-error
ETQ instructeur, message d'erreur plutôt que crash lorsqu'on ajoute un filtre trop long (plus de 100 caractères)
This commit is contained in:
commit
8579736c03
3 changed files with 29 additions and 7 deletions
|
@ -148,7 +148,9 @@ module Instructeurs
|
|||
end
|
||||
|
||||
def add_filter
|
||||
procedure_presentation.add_filter(statut, params[:field], params[:value])
|
||||
if !procedure_presentation.add_filter(statut, params[:field], params[:value])
|
||||
flash.alert = procedure_presentation.errors.full_messages
|
||||
end
|
||||
|
||||
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
||||
end
|
||||
|
|
|
@ -319,7 +319,7 @@ class ProcedurePresentation < ApplicationRecord
|
|||
'value' => value
|
||||
}
|
||||
|
||||
update!(filters: updated_filters)
|
||||
update(filters: updated_filters)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -457,11 +457,11 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
|
||||
def check_filters_max_length
|
||||
individual_filters = filters.values.flatten.filter { |f| f.is_a?(Hash) }
|
||||
individual_filters.each do |filter|
|
||||
if filter['value']&.length.to_i > FILTERS_VALUE_MAX_LENGTH
|
||||
errors.add(:filters, :too_long)
|
||||
end
|
||||
filters.values.flatten.each do |filter|
|
||||
next if !filter.is_a?(Hash)
|
||||
next if filter['value']&.length.to_i <= FILTERS_VALUE_MAX_LENGTH
|
||||
|
||||
errors.add(:base, "Le filtre #{filter['label']} est trop long (maximum: #{FILTERS_VALUE_MAX_LENGTH} caractères)")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -830,4 +830,24 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
it { is_expected.to have_http_status(:forbidden) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#add_filter' do
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
let(:procedure) { create(:procedure, :for_individual) }
|
||||
|
||||
before do
|
||||
create(:assign_to, instructeur:, groupe_instructeur: build(:groupe_instructeur, procedure:))
|
||||
|
||||
sign_in(instructeur.user)
|
||||
end
|
||||
|
||||
subject do
|
||||
post :add_filter, params: { procedure_id: procedure.id, field: "individual/nom", value: "n" * 110, 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)")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue