Tuesday, May 12, 2009

No Meals

Having played a bit with meals, I got to wondering what would happen with the recipe couchdb-lucene index if meals were added to the DB. Rather than wonder about it, I'm going to prove it:

Scenario: Searching recipes with meals and other things in the DB

Given 5 "Yummy" recipes And 1 "Yummy" meal And 1 "About this site" document with the word "Yummy" in it And a 0.5 second wait to allow the search index to be updated When I search for "yummy" Then I should see 5 results

Most of these steps are already implemented, but the meal and "About this site" steps are not. They can be defined as:

Running the scenario generates a big old ball of fail, as expected. Nothing is preventing these new documents from being added to the couchdb-lucene index, but I do not want them in there. I only want to search recipes.

A simple conditional in the indexing javascipt function will do the trick:

if (doc['preparations']) {... }

The conditional exploits the lack of a prepartions attribute in any document other than recipes. Effectively, I index a document only if it quack likes a recipe.

With that, I have my new scenario completely passing:

cstrom@jaynestown:~/repos/eee-code$ cucumber -n features \ -s "Searching recipes with meals and other things in the DB"Feature: Search for recipes

So that I can find one recipe among many As a web user I want to be able search recipes

Scenario: Searching recipes with meals and other things in the DB Given 5 "Yummy" recipes And 1 "Yummy" meal And 1 "About this site" document with the word "Yummy" in it And a 0.5 second wait to allow the search index to be updated When I search for "yummy" Then I should see 5 results

1 scenario6 passed steps

Before committing, some older scenarios needed adjustment to ensure that simple recipe documents that they were creating also quacked like a recipe.(commit)