From e90481ce3de898190f3a45584f571644ff7c9f97 Mon Sep 17 00:00:00 2001 From: eee-c Date: Wed, 22 Apr 2009 23:23:46 -0400 Subject: [PATCH] First 4 steps of the pagination scenario --- eee.rb | 2 +- features/recipe_search.feature | 6 +++--- features/step_definitions/recipe_search.rb | 21 +++++++++++++++++++++ features/support/env.rb | 4 ++++ spec/eee_spec.rb | 12 ++++++++++-- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/eee.rb b/eee.rb index 138e869..21e56bf 100644 --- a/eee.rb +++ b/eee.rb @@ -17,7 +17,7 @@ end get '/recipes/search' do - data = RestClient.get "#{@@db}/_fti?q=#{params[:q]}" + data = RestClient.get "#{@@db}/_fti?limit=20&q=#{params[:q]}" @results = JSON.parse(data) haml :search diff --git a/features/recipe_search.feature b/features/recipe_search.feature index 2a3bee8..db019da 100644 --- a/features/recipe_search.feature +++ b/features/recipe_search.feature @@ -57,13 +57,13 @@ Feature: Search for recipes Then I should see 20 results And 3 pages of results And I should not be able to go to a previous page - When I visit page 3 + When I click page 3 Then I should see 10 results And I should not be able to go to a next page - When I visit the previous page + When I click the previous page Then I should see 20 results And I should be able to go to a previous page - When I visit the next page + When I click the next page Then I should see 10 results When I visit page -1 Then I should see page 1 diff --git a/features/step_definitions/recipe_search.rb b/features/step_definitions/recipe_search.rb index 2b6a7ac..9c3f2df 100644 --- a/features/step_definitions/recipe_search.rb +++ b/features/step_definitions/recipe_search.rb @@ -107,6 +107,23 @@ :content_type => 'application/json' end +Given /^(\d+) (.+) recipes$/ do |count, keyword| + date = Date.new(2009, 4, 22) + + (0..count.to_i).each do |i| + permalink = "id-#{i}-#{keyword.gsub(/\W/, '-')}" + + @pancake_recipe = { + :title => "#{keyword} recipe #{i}", + :date => date + } + + RestClient.put "#{@@db}/#{permalink}", + @pancake_recipe.to_json, + :content_type => 'application/json' + end +end + Given /^a ([.\d]+) second wait/ do |seconds| sleep seconds.to_f end @@ -132,3 +149,7 @@ Then /^I should not see the "(.+)" recipe in the search results$/ do |title| response.should_not have_selector("a", :content => title) end + +Then /^I should see (\d+) results$/ do |count| + response.should have_selector("table a", :count => count.to_i) +end diff --git a/features/support/env.rb b/features/support/env.rb index 78b6edb..e93cbb3 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -4,6 +4,10 @@ # sinatra will look in the wrong place for its views. require File.dirname(__FILE__) + '/../../eee' +# Force the application name because polyglot breaks the auto-detection logic. +Sinatra::Application.app_file = File.join(File.dirname(__FILE__), *%w[.. .. eee.rb]) + + # RSpec matchers require 'spec/expectations' diff --git a/spec/eee_spec.rb b/spec/eee_spec.rb index 54c2227..14416f3 100644 --- a/spec/eee_spec.rb +++ b/spec/eee_spec.rb @@ -63,7 +63,7 @@ describe "GET /recipes/search" do it "should retrieve search results from couchdb-lucene" do RestClient.should_receive(:get). - with("#{@@db}/_fti?q=eggs"). + with(/_fti\?.*q=eggs/). and_return('{"total_rows":1,"rows":[]}') get "/recipes/search?q=eggs" @@ -71,7 +71,15 @@ it "should not include the \"all\" field when performing fielded searches" do RestClient.should_receive(:get). - with("#{@@db}/_fti?q=title:eggs"). + with(/q=title:eggs/). + and_return('{"total_rows":1,"rows":[]}') + + get "/recipes/search?q=title:eggs" + end + + it "should have pages sizes of 20 records" do + RestClient.should_receive(:get). + with(/limit=20/). and_return('{"total_rows":1,"rows":[]}') get "/recipes/search?q=title:eggs"