Add some more tests, better error handling for dates
This commit is contained in:
parent
5f1f8f3c91
commit
e8cb7ac8f1
2 changed files with 87 additions and 12 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue