Merge pull request #501 from sgmap/attestation_force_footer_to_fit_on_one_line

Attestation force footer to fit on one line and limit its length
This commit is contained in:
gregoirenovel 2017-06-27 13:41:40 +02:00 committed by GitHub
commit 8d24f08f4c
4 changed files with 21 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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')