From 4de4612aa709aecbe2893fd0a2d3008379cd3b5d Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Thu, 1 Aug 2019 11:19:40 +0200 Subject: [PATCH] clearer error message for dates. #326 --- app/models/doi.rb | 2 +- spec/models/doi_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/doi.rb b/app/models/doi.rb index 5dd0341f3..d6f88cd50 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -746,7 +746,7 @@ def event=(value) def check_dates Array.wrap(dates).each do |d| - errors.add(:dates, "Date #{d["date"]} is not in a supported format.") unless Date.edtf(d["date"]).present? + errors.add(:dates, "Date #{d["date"]} is not a valid date in ISO8601 format.") unless Date.edtf(d["date"]).present? end end diff --git a/spec/models/doi_spec.rb b/spec/models/doi_spec.rb index 1813c1cc6..e44b688a1 100644 --- a/spec/models/doi_spec.rb +++ b/spec/models/doi_spec.rb @@ -258,13 +258,13 @@ it "invalid" do doi.dates = [{ "date" => "08/01/2019" }] expect(doi.save).to be false - expect(doi.errors.details).to eq(:dates=>[{:error=>"Date 08/01/2019 is not in a supported format."}]) + expect(doi.errors.details).to eq(:dates=>[{:error=>"Date 08/01/2019 is not a valid date in ISO8601 format."}]) end it "invalid datetime" do doi.dates = [{ "date" => "2019-08-01 20:28:15" }] expect(doi.save).to be false - expect(doi.errors.details).to eq(:dates => [{:error=>"Date 2019-08-01 20:28:15 is not in a supported format."}]) + expect(doi.errors.details).to eq(:dates => [{:error=>"Date 2019-08-01 20:28:15 is not a valid date in ISO8601 format."}]) end end