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 5c50f5023..9b54d4def 100644 --- a/app/views/admin/attestation_templates/edit.html.haml +++ b/app/views/admin/attestation_templates/edit.html.haml @@ -58,8 +58,7 @@ .form-group = f.label :footer, 'Adresse en bas de page' - ~ f.text_area :footer, class: 'form-control', rows: 2, - placeholder: "Direction interministérielle du numérique et du système d'information et de communication de l'Etat (DINSIC)" + = 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')