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:
commit
5f826cfd88
2 changed files with 9 additions and 2 deletions
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue