fix multiple error message on regexp
This commit is contained in:
parent
256d63e5f3
commit
2bec15b78f
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