small medium large xlarge

Generic-user-small
29 Oct 2014, 15:28
Mike Hostetler (2 posts)

I’m not a Ruby person and can be a bit daft sometimes but I can’t get the “sort by date” test working correctly.


# from app.rb

 get "/bookmarks/date" do

   content_type :json
   bookmarks= Bookmark.all(:order=>[:created_at.desc])
   bookmarks.to_json
  
end


#from app_test.rb

it "gets by most recent first" do
   post "/bookmarks", {:url=> "http://www.test.com",:title=>"Test"}

   bookmark_uri = last_response.body
   id = bookmark_uri.split("/").last

   get "/bookmarks/date"
 
   last_response.status.should==200

   last_response.body.should_not==nil
   last_response.body.should_not==""
 
   bookmarks = JSON.parse(last_response.body)

   mark = bookmarks[0]

   expect(mark.id).to eq (id)

end


When I run the test I get:


Failures:

1) bookmark application gets by most recent first
   Failure/Error: bookmarks = JSON.parse(last_response.body)
   JSON::ParserError:
   757: unexpected token at 'null'
 # /Library/Ruby/Gems/2.0.0/gems/json_pure-1.8.1/lib/json/common.rb:155:in `parse'
 # /Library/Ruby/Gems/2.0.0/gems/json_pure-1.8.1/lib/json/common.rb:155:in `parse'
 # ./app_test.rb:80:in `block (2 levels) in <top (required)>'

I make sure that there were no nulls in the table (I got bit by the input putting in nulls - thanks drblinken) but I don’t have any.

anyone have ideas?

You must be logged in to comment