models: improve error message for invalid champs
Avoid prepending the message with 'Draft revision '
This commit is contained in:
parent
b86dec8251
commit
99c77046d2
5 changed files with 10 additions and 6 deletions
|
@ -1,7 +1,7 @@
|
||||||
class SiretFormatValidator < ActiveModel::EachValidator
|
class SiretFormatValidator < ActiveModel::EachValidator
|
||||||
def validate_each(record, attribute, value)
|
def validate_each(record, attribute, value)
|
||||||
if !format_is_valid(value)
|
if !format_is_valid(value)
|
||||||
record.errors.add(attribute, :format)
|
record.errors.add(attribute, :length)
|
||||||
end
|
end
|
||||||
|
|
||||||
if !luhn_passed(value)
|
if !luhn_passed(value)
|
||||||
|
|
|
@ -51,6 +51,9 @@ module TPS
|
||||||
# Set the queue name for the mail delivery jobs to 'mailers'
|
# Set the queue name for the mail delivery jobs to 'mailers'
|
||||||
config.action_mailer.deliver_later_queue_name = :mailers
|
config.action_mailer.deliver_later_queue_name = :mailers
|
||||||
|
|
||||||
|
# Allow the error messages format to be customized
|
||||||
|
config.active_model.i18n_customize_full_message = true
|
||||||
|
|
||||||
# Set the queue name for the analysis jobs to 'active_storage_analysis'
|
# Set the queue name for the analysis jobs to 'active_storage_analysis'
|
||||||
config.active_storage.queues.analysis = :active_storage_analysis
|
config.active_storage.queues.analysis = :active_storage_analysis
|
||||||
|
|
||||||
|
|
|
@ -23,4 +23,5 @@ fr:
|
||||||
attributes:
|
attributes:
|
||||||
api_particulier_token:
|
api_particulier_token:
|
||||||
invalid: 'n’a pas le bon format'
|
invalid: 'n’a pas le bon format'
|
||||||
|
draft_revision:
|
||||||
|
format: '%{message}'
|
||||||
|
|
|
@ -10,6 +10,6 @@ fr:
|
||||||
siret:
|
siret:
|
||||||
attributes:
|
attributes:
|
||||||
siret:
|
siret:
|
||||||
format: 'Le numéro SIRET doit comporter 14 chiffres'
|
length: 'Le numéro SIRET doit comporter 14 chiffres'
|
||||||
checksum: 'Le numéro SIRET comporte une erreur, vérifiez les chiffres composant le numéro'
|
checksum: 'Le numéro SIRET comporte une erreur, vérifiez les chiffres composant le numéro'
|
||||||
invalid: 'Le numéro SIRET ne correspond pas à un établissement existant'
|
invalid: 'Le numéro SIRET ne correspond pas à un établissement existant'
|
||||||
|
|
|
@ -297,21 +297,21 @@ describe Procedure do
|
||||||
|
|
||||||
it 'validates that no repetition type de champ is empty' do
|
it 'validates that no repetition type de champ is empty' do
|
||||||
procedure.validate
|
procedure.validate
|
||||||
expect(procedure.errors[:draft_revision]).to include(invalid_repetition_error_message)
|
expect(procedure.errors.full_messages_for(:draft_revision)).to include(invalid_repetition_error_message)
|
||||||
|
|
||||||
text_field.revision = repetition.revision
|
text_field.revision = repetition.revision
|
||||||
text_field.order_place = repetition.types_de_champ.size
|
text_field.order_place = repetition.types_de_champ.size
|
||||||
procedure.draft_revision.types_de_champ.find(&:repetition?).types_de_champ << text_field
|
procedure.draft_revision.types_de_champ.find(&:repetition?).types_de_champ << text_field
|
||||||
|
|
||||||
procedure.validate
|
procedure.validate
|
||||||
expect(procedure.errors[:draft_revision]).not_to include(invalid_repetition_error_message)
|
expect(procedure.errors.full_messages_for(:draft_revision)).not_to include(invalid_repetition_error_message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when validating for publication' do
|
context 'when validating for publication' do
|
||||||
it 'validates that no repetition type de champ is empty' do
|
it 'validates that no repetition type de champ is empty' do
|
||||||
procedure.validate(:publication)
|
procedure.validate(:publication)
|
||||||
expect(procedure.errors[:draft_revision]).to include(invalid_repetition_error_message)
|
expect(procedure.errors.full_messages_for(:draft_revision)).to include(invalid_repetition_error_message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue