Merge pull request #855 from sgmap/fix_attestation_date
[fix #845] Attestation: affiche les dates au format français
This commit is contained in:
commit
fb7ff848af
3 changed files with 43 additions and 4 deletions
|
@ -124,12 +124,11 @@ class AttestationTemplate < ApplicationRecord
|
|||
|
||||
def replace_type_de_champ_tags(text, types_de_champ, dossier_champs)
|
||||
types_de_champ.inject(text) do |acc, tag|
|
||||
value = dossier_champs
|
||||
.select { |champ| champ.libelle == tag[:libelle] }
|
||||
champ = dossier_champs
|
||||
.select { |dossier_champ| dossier_champ.libelle == tag[:libelle] }
|
||||
.first
|
||||
.value
|
||||
|
||||
acc.gsub("--#{tag[:libelle]}--", value.to_s)
|
||||
acc.gsub("--#{tag[:libelle]}--", champ.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -57,6 +57,19 @@ class Champ < ActiveRecord::Base
|
|||
JSON.parse(Carto::GeoAPI::Driver.pays).inject([]) { |acc, liste| acc.push(liste['nom']) }
|
||||
end
|
||||
|
||||
def to_s
|
||||
if value.present?
|
||||
case type_champ
|
||||
when 'date'
|
||||
Date.parse(value).strftime('%d/%m/%Y')
|
||||
else
|
||||
value.to_s
|
||||
end
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_date_to_iso
|
||||
|
|
|
@ -255,5 +255,32 @@ describe AttestationTemplate, type: :model do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the procedure has 2 types de champ date and datetime' do
|
||||
let(:types_de_champ) do
|
||||
[create(:type_de_champ_public, libelle: 'date', type_champ: 'date'),
|
||||
create(:type_de_champ_public, libelle: 'datetime', type_champ: 'datetime')]
|
||||
end
|
||||
|
||||
context 'and the are used in the template title' do
|
||||
let(:template_title) { 'title --date-- --datetime--' }
|
||||
|
||||
context 'and its value in the dossier are not nil' do
|
||||
before :each do
|
||||
dossier.champs
|
||||
.select { |champ| champ.type_champ == 'date' }
|
||||
.first
|
||||
.value = '2017-04-15'
|
||||
|
||||
dossier.champs
|
||||
.select { |champ| champ.type_champ == 'datetime' }
|
||||
.first
|
||||
.value = '13/09/2017 09:00'
|
||||
end
|
||||
|
||||
it { expect(view_args[:title]).to eq('title 15/04/2017 13/09/2017 09:00') }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue