From e5f3c39ffeaf6f6e7467cff09676158da92366ac Mon Sep 17 00:00:00 2001 From: eee-c Date: Thu, 7 May 2009 22:10:15 -0400 Subject: [PATCH] Fix a mistake moving past the pagination window --- eee.rb | 4 ++-- spec/eee_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/eee.rb b/eee.rb index e4eb0a6..055457d 100644 --- a/eee.rb +++ b/eee.rb @@ -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 diff --git a/spec/eee_spec.rb b/spec/eee_spec.rb index cb7e74c..2bf0d6d 100644 --- a/spec/eee_spec.rb +++ b/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 @@ -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)