Skip to content

Commit

Permalink
clearer error message for dates. #326
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Aug 1, 2019
1 parent 7be7cf1 commit 4de4612
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions spec/models/doi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4de4612

Please sign in to comment.