From c866cf4d3c435c074bbe99a96d782fe358f21933 Mon Sep 17 00:00:00 2001 From: eee-c Date: Sun, 19 Apr 2009 22:48:36 -0400 Subject: [PATCH] Implementing the search titles scenario --- eee.rb | 3 ++- features/recipe_search.feature | 8 +++++--- features/step_definitions/recipe_search.rb | 19 +++++++++++++++++++ spec/eee_spec.rb | 8 ++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/eee.rb b/eee.rb index 7b6fd8b..42410f5 100644 --- a/eee.rb +++ b/eee.rb @@ -17,7 +17,8 @@ end get '/recipes/search' do - data = RestClient.get "#{@@db}/_fti?q=all:#{params[:q]}" + query = "all:#{params[:q]}".sub(/(\w+):(\w+):/, "\\2:") + data = RestClient.get "#{@@db}/_fti?q=#{query}" @results = JSON.parse(data) haml :search diff --git a/features/recipe_search.feature b/features/recipe_search.feature index 2248cfe..2e6ec31 100644 --- a/features/recipe_search.feature +++ b/features/recipe_search.feature @@ -34,8 +34,8 @@ Feature: Search for recipes Scenario: Searching titles Given a "pancake" recipe - And a "french toast" recipe with a summary of "not a pancake" - And a 1 second wait to allow the search index to be updated + And a "french toast" recipe with a "not a pancake" summary + And a 0.25 second wait to allow the search index to be updated When I search titles for "pancake" Then I should see the "pancake" recipe in the search results And I should not see the "french toast" recipe in the search results @@ -44,7 +44,7 @@ Feature: Search for recipes Given a "pancake" recipe with "chocolate chips" in it And a "french toast" recipe with eggs in it and a summary of "does not go well with chocolate" - And a 1 second wait to allow the search index to be updated + And a 0.25 second wait to allow the search index to be updated When I search ingredients for "chocolate" Then I should see the "pancake" recipe in the search results And I should not see the "french toast" recipe in the search results @@ -54,3 +54,5 @@ Feature: Search for recipes Scenario: Sorting (name, date, preparation time, number of ingredients) Scenario: No matching results + + Scenario: Invalid search parameters diff --git a/features/step_definitions/recipe_search.rb b/features/step_definitions/recipe_search.rb index 26e53ff..591f7c0 100644 --- a/features/step_definitions/recipe_search.rb +++ b/features/step_definitions/recipe_search.rb @@ -70,6 +70,21 @@ :content_type => 'application/json' end +Given /^a "(.+)" recipe$/ do |title| + date = Date.new(2009, 4, 19) + permalink = "id-#{title.gsub(/\W/, '-')}" + + recipe = { + :title => title, + :date => date, + } + + RestClient.put "#{@@db}/#{permalink}", + recipe.to_json, + :content_type => 'application/json' +end + + Given /^a ([.\d]+) second wait/ do |seconds| sleep seconds.to_f end @@ -78,6 +93,10 @@ visit("/recipes/search?q=#{keyword}") end +When /^I search titles for "(.+)"$/ do |keyword| + visit("/recipes/search?q=title:#{keyword}") +end + Then /^I should see the "(.+)" recipe in the search results$/ do |title| response.should have_selector("a", :href => "/recipes/id-#{title.gsub(/\W/, '-')}", diff --git a/spec/eee_spec.rb b/spec/eee_spec.rb index 45c1d3c..aef9826 100644 --- a/spec/eee_spec.rb +++ b/spec/eee_spec.rb @@ -68,5 +68,13 @@ 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"). + and_return('{"total_rows":1,"rows":[]}') + + get "/recipes/search?q=title:eggs" + end end end