Monday, April 27, 2009

Sorting Stories

‹prev | My Chain | next›

With the pagination work behind me, I need to get sorting working. Sorting will default to ascending order, except for dates (most recent date should be first). When I am on a page after the first and sort by a different field, pagination should start back on page 1. When I am on a page after the first and reverse the sort order, I should also be taken back to page 1. The scenario that describes this is:
    Scenario: Sorting (name, date, preparation time, number of ingredients)

Given 50 "delicious" recipes with ascending names, dates, preparation times, and number of ingredients
And of 0.5 second wait to allow the search index to be updated
When I search for "delicious"
Then I should see 20 results
When I click the "Name" column header
Then the results should be ordered by name in ascending order
When I click the "Name" column header
Then the results should be ordered by name in descending order
When I click the next page
Then I should see page 2
And the results should be ordered by name in descending order
When I click the "Date" column header
Then I should see page 1
And the results should be ordered by date in descending order
When I click the next page
Then I should see page 2
When I click the "Date" column header
Then the results should be ordered by date in ascending order
And I should see page 1
When I click the "Prep" column header
Then the results should be ordered by preparation time in ascending order
When I click the "Ingredients" column header
Then the results should be ordered by the number of ingredients in ascending order
The final two scenarios in the search feature are boundary conditions: no matching results and invalid search parameters. The fully described scenarios:
    Scenario: No matching results

Given 5 "Yummy" recipes
And of 0.5 second wait to allow the search index to be updated
When I search for "delicious"
Then I should see no results
And no result headings


Scenario: Invalid search parameters

Given 5 "Yummy" recipes
And of 0.5 second wait to allow the search index to be updated
When I search for ""
Then I should see no results
When I seach for a pre-ascii character "%1F"
Then I should see no results
And an empty query string
When I search for an invalid lucene search term like "title:ingredient:egg"
Then I should see no results
And an empty query string
(commit)

Whoops

While verifying the Cucumber format of the new scenarios, I notice that I have broken my first search scenario (note to self, you're not done with new scenarios if old ones are broken):
cstrom@jaynestown:~/repos/eee-code$ cucumber features/recipe_search.feature \
> -n -s "Matching a word in the ingredient list in full recipe search"
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: Matching a word in the ingredient list in full recipe search
Given a "pancake" recipe with "chocolate chips" in it
And a "french toast" recipe with "eggs" in it
And a 0.5 second wait to allow the search index to be updated
When I search for "chocolate"
Then I should see the "pancake" recipe in the search results
expected following output to contain a <a href='/recipes/id-pancake'>pancake</a> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
<table><tr>
<th>Name</th>
<th>Date</th>
</tr></table>
<div class="pagination">
<span class="inactive">« Previous</span><a href="/recipes/search?q=chocolate&page=2">Next »</a>
</div>
</body></html>
(Spec::Expectations::ExpectationNotMetError)
features/recipe_search.feature:13:in `Then I should see the "pancake" recipe in the search results'
And I should not see the "french toast" recipe in the search results

1 scenario
1 failed step
1 skipped step
4 passed steps
It turns out that this failure has uncovered a bug that I have introduced in the code. Specifically, I am not including ingredients in the default, 'all' field of the couchdb-lucene index. To resolve, I need to add it to the couchdb-lucene _design/lucene transform design document:
            ret.field('ingredient', ingredients.join(', '), 'yes');
ret.field('all', ingredients.join(', '));
With that, I am back in the green:



(commit)

No comments:

Post a Comment