From 3d9940749581e5566494bb73c658463055f2cbc6 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 27 Jun 2017 13:07:06 +0200 Subject: [PATCH] [Fix #499] Attestation: add maxlength to footer --- app/models/attestation_template.rb | 1 + .../admin/attestation_templates/edit.html.haml | 2 +- config/locales/fr.yml | 4 ++++ spec/models/attestation_template_spec.rb | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/models/attestation_template.rb b/app/models/attestation_template.rb index 9bac00521..9c2b5ad49 100644 --- a/app/models/attestation_template.rb +++ b/app/models/attestation_template.rb @@ -7,6 +7,7 @@ class AttestationTemplate < ApplicationRecord mount_uploader :signature, AttestationTemplateImageUploader validate :logo_signature_file_size + validates :footer, length: { maximum: 190 } FILE_MAX_SIZE_IN_MB = 0.5 diff --git a/app/views/admin/attestation_templates/edit.html.haml b/app/views/admin/attestation_templates/edit.html.haml index 43bbab1fa..9b54d4def 100644 --- a/app/views/admin/attestation_templates/edit.html.haml +++ b/app/views/admin/attestation_templates/edit.html.haml @@ -58,7 +58,7 @@ .form-group = f.label :footer, 'Adresse en bas de page' - = f.text_field :footer, class: 'form-control' + = f.text_field :footer, class: 'form-control', maxlength: 190 %button.btn.btn-primary{ formaction: admin_procedure_attestation_template_preview_path, formtarget: '_blank' } Prévisualiser diff --git a/config/locales/fr.yml b/config/locales/fr.yml index f1da0acaa..b94806305 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -87,6 +87,10 @@ fr: activerecord: errors: models: + attestation_template: + attributes: + footer: + too_long: ": l'adresse en bas de page est trop longue." piece_justificative: attributes: content: diff --git a/spec/models/attestation_template_spec.rb b/spec/models/attestation_template_spec.rb index a9d5e5191..95270dbb9 100644 --- a/spec/models/attestation_template_spec.rb +++ b/spec/models/attestation_template_spec.rb @@ -40,6 +40,21 @@ describe AttestationTemplate, type: :model do end end + describe 'validates footer length' do + let(:attestation_template) { AttestationTemplate.new(footer: footer) } + + subject do + attestation_template.validate + attestation_template.errors.details + end + + context 'when the footer is too long' do + let(:footer) { 'a' * 191 } + + it { is_expected.to match({ footer: [{ error: :too_long, count: 190 }] }) } + end + end + describe 'dup' do before do @logo = File.open('spec/fixtures/white.png')