Merge pull request #10095 from demarches-simplifiees/fix_multiple_error_message_on_regexp

Admin: corrige un bug ou un message d'erreur d expression regulière apparaissait plusieurs fois
This commit is contained in:
Colin Darie 2024-03-12 13:07:25 +00:00 committed by GitHub
commit 5f826cfd88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View file

@ -649,6 +649,9 @@ class TypeDeChamp < ApplicationRecord
end
def invalid_regexp?
self.errors.delete(:expression_reguliere)
self.errors.delete(:expression_reguliere_exemple_text)
return false if expression_reguliere.blank?
return false if expression_reguliere_exemple_text.blank?
return false if expression_reguliere_exemple_text.match?(Regexp.new(expression_reguliere, timeout: ExpressionReguliereValidator::TIMEOUT))

View file

@ -174,9 +174,13 @@ describe TypeDeChamp do
let(:expression_reguliere_exemple_text) { "01234567" }
let(:expression_reguliere) { "[A-Z]+" }
it "should add error message" do
it "should add only one error message" do
expect(subject).to be_truthy
expect(tdc.errors.messages[:expression_reguliere_exemple_text]).to be_present
expect(tdc.errors.messages[:expression_reguliere_exemple_text].size).to eq(1)
tdc.invalid_regexp?
expect(tdc.errors.messages[:expression_reguliere_exemple_text].size).to eq(1)
end
end