Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First 4 steps of the pagination scenario
  • Loading branch information
eee-c committed Apr 23, 2009
1 parent 6014732 commit e90481c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion eee.rb
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions features/recipe_search.feature
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions features/step_definitions/recipe_search.rb
Expand Up @@ -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
Expand All @@ -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
4 changes: 4 additions & 0 deletions features/support/env.rb
Expand Up @@ -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'

Expand Down
12 changes: 10 additions & 2 deletions spec/eee_spec.rb
Expand Up @@ -63,15 +63,23 @@
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"
end

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"
Expand Down

0 comments on commit e90481c

Please sign in to comment.