Skip to content

Commit

Permalink
Fix a mistake moving past the pagination window
Browse files Browse the repository at this point in the history
  • Loading branch information
eee-c committed May 8, 2009
1 parent 52594c6 commit e5f3c39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions eee.rb
Expand Up @@ -36,10 +36,10 @@
@results = JSON.parse(data)
rescue Exception
@query = ""
@results = { 'total_rows' => 0 }
@results = { 'total_rows' => 0, 'rows' => [] }
end

if @results['total_rows'] == 0 && page > 1
if @results['rows'].count == 0 && page > 1
redirect("/recipes/search?q=#{@query}")
return
end
Expand Down
11 changes: 11 additions & 0 deletions spec/eee_spec.rb
@@ -1,4 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper' )
require 'pp'

describe "eee" do
include Sinatra::Test
Expand Down Expand Up @@ -140,6 +141,16 @@
response.should contain("No results")
end

it "should redirect without pagination after navigating beyond the pagination window" do
RestClient.stub!(:get).
and_return('{"total_rows":1,"skip":0,"limit":20,"rows":[]}')

get "/recipes/search?q=egg&page=2"

response.status.should == 302
response.headers["Location"].should == "/recipes/search?q=egg"
end

it "should treat couchdb errors as no-results" do
RestClient.stub!(:get).
and_raise(Exception)
Expand Down

0 comments on commit e5f3c39

Please sign in to comment.