Merge pull request #8864 from colinux/fix-date-not-parseable

fix(date): ne crash pas lorsqu'un champ date n'as pas une date standard
This commit is contained in:
Paul Chavard 2023-04-05 11:48:48 +00:00 committed by GitHub
commit b8f639721e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -30,11 +30,11 @@ class Champs::DateChamp < Champ
def to_s
value.present? ? I18n.l(Time.zone.parse(value), format: '%d %B %Y') : ""
rescue ArgumentError
value.presence || "" # old dossiers can have not parseable dates
end
def for_tag
value.present? ? I18n.l(Time.zone.parse(value), format: '%d %B %Y') : ""
end
alias for_tag to_s
private

View file

@ -45,6 +45,18 @@ describe Champs::DateChamp do
end
end
describe "#to_s" do
it "format the date" do
champ_with_value("2020-06-20")
expect(date_champ.to_s).to eq("20 juin 2020")
end
it "does not fail when value is not iso" do
champ_with_value("2023-30-01")
expect(date_champ.to_s).to eq("2023-30-01")
end
end
def champ_with_value(number)
date_champ.tap { |c| c.value = number }
end