Add some more tests, better error handling for dates

This commit is contained in:
ENT8R 2018-08-27 16:44:46 +02:00
parent 5f1f8f3c91
commit e8cb7ac8f1
No known key found for this signature in database
GPG key ID: F157C7F553A0FAC4
2 changed files with 87 additions and 12 deletions

View file

@ -280,18 +280,19 @@ class NotesController < ApplicationController
# Filter by a given start date and an optional end date
if params[:from]
from = Time.parse(params[:from])
to = if params[:to]
Time.parse(params[:to])
else
Time.now
end
if from && to
@notes = @notes.where("(created_at > '#{from}' AND created_at < '#{to}')")
else
begin
from = Time.parse(params[:from])
to = if params[:to]
Time.parse(params[:to])
else
Time.now
end
rescue ArgumentError
# return a more generic error so that everybody knows what is wrong
raise OSM::APIBadUserInput, "The date is in a wrong format"
end
@notes = @notes.where("(created_at > '#{from}' AND created_at < '#{to}')")
end
# Find the notes we want to return