Tuesday, June 9, 2009

Between Meals (Inside)

‹prev | My Chain | next›

Gonna be a bit brief today as I was presenting at the B'More on Rails users' group tonight. Still, I must make my daily offering to the chain gods, lest I fall into disfavor with them.

I left off last night with a failing Cucumber scenario:
cstrom@jaynestown:~/repos/eee-code$ cucumber features -n -s "Navigating between meals"
Sinatra::Test is deprecated; use Rack::Test instead.
Feature: Browse Meals

So that I can find meals made on special occasions
As a person interested in finding meals
I want to browse meals by date

Scenario: Navigating between meals
Given a "Pumpkin is a Very Exciting Vegetable" meal enjoyed on December 3, 2008
And a "Star Wars: The Dinner" meal enjoyed on February 28, 2009
And a "Focaccia! The Dinner" meal enjoyed on March 3, 2009
When I view the "Focaccia! The Dinner" meal
Then I should see the "Focaccia! The Dinner" title
When I click "Star Wars: The Dinner"
Could not find link with text or title or id "Star Wars: The Dinner" (Webrat::NotFoundError)
features/browse_meals.feature:61:in `When I click "Star Wars: The Dinner"'

Then I should see the "Star Wars: The Dinner" title
When I click "Pumpkin is a Very Exciting Vegetable"
Then I should see the "Pumpkin is a Very Exciting Vegetable" title
When I click "Star Wars: The Dinner"
Then I should see the "Star Wars: The Dinner" title
When I click "Focaccia! The Dinner"
Then I should see the "Focaccia! The Dinner" title

1 scenario
1 failed step
7 skipped steps
5 passed steps
For this, I will need a another CouchDB view that returns a date ordered list of meals:
{
"views": {
...
"by_date": {
"map": "function (doc) {
if (doc['type'] == 'Meal') {
emit(doc['date'], [doc['_id'], doc['title']]);
}
}"
},
...
}
}
I still have yet to find a way to drive the development of CouchDB Javascript views by example, so I will rely on the Cucumber scenario to verify that view. For now, I will use RSpec to describe how I want to use it in the meal Haml spec:
describe "meal.haml" do
before(:each) do
@title = "Meal Title"
@summary = "Meal Summary"
@description = "Meal Description"
@year = 2009
@month = 5
assigns[:meal] = @meal = {
'date' => "%d-%02d-31" % [@year, @month],
'title' => @title,
'summary' => @summary,
'description' => @description,
'menu' => ["Peanut Butter and Jelly Sandwich"]
}
assigns[:meals_by_date] = [{"key" => "2009-05-15", "value" => []},
{"key" => "2009-05-31", "value" => []}]

end
...
it "should link to previous meal" do
render("/views/meal.haml")
response.should have_selector("a", :href => "/meals/2009/05/15")
end

...
end
I already have a helper that pulls adjacent dates out of CouchDB views, I re-use this to implement that example:
...
%h1
= @meal['title']

%div.navigation
=link_to_adjacent_view_date(@meal['date'], @meals_by_date, :previous => true)
|
=link_to_adjacent_view_date(@meal['date'], @meals_by_date)
...
A CouchDB view and a simple implementation are enough for me to satisfy the gods tonight. I will pick back up tomorrow by linking humanized dates (it is now linking text like "2009-06-09") and then working my way back out to the Cucumber scenario to see if I am done with this scenario.
(commit)

No comments:

Post a Comment