Sunday, June 14, 2009

Meal Photos and Menu Items

‹prev | My Chain | next›

Today, I continue work on the navigation-from-the-homepage Cucumber scenario. Yesterday, I was able to include meal summaries on the homepage. The next two steps in the scenario are additional "thens" (post-conditions) verifying that a meal thumbnail and menu items are also included on the homepage.

Nothing new needs to be added to the Sinatra application to include either of these pieces of information. This means that work today begins with the Haml specification to drive the new data presentation.

The example of how I'd like the thumbnail to display:
  it "should include a thumbnail image of the meal" do
response.should have_selector("img",
:src => "/images/2009-05-15/image1.jpg",
:width => "200",
:height => "150")
I already have an image_link helper, so I can make this example pass with a simple call to that helper:
    = image_link meal, :width => 200, :height => 150
Next, I need two examples describing the presentation of each meal's menu items on the homepage. They should be wikified and comma separated:
  it "should include a comma separated list of menu items" do
assigns[:meals][0]["menu"] << "chips"
assigns[:meals][0]["menu"] << "salsa"
response.should have_selector(".menu-items",
:content => "chips, salsa")

it "should wikify menu items" do
assigns[:meals][0]["menu"] << "_really_ hot salsa"
response.should have_selector(".menu-items em",
:content => "really")
The entire index.haml template that implements this:
%h1 Meals
- @meals.each do |meal|
= image_link meal, :width => 200, :height => 150
%h2= meal["title"]
= wiki(meal["summary"])
.menu-items= wiki(meal["menu"].join(", "))
With that, I am done with my inside/code work for today. Working my was back out to the Cucumber scenario, I need to include an image attachment if I expect to include it in the homepage:
Given /^(\d+) yummy meals$/ do |count|
start_date =, 6, 11)

@meal_ids = (0...count.to_i).inject([]) do |memo, i|
date = start_date - (i * 10)

meal = {
:title => "Meal #{i}",
:date => date.to_s,
:serves => 4,
:summary => "meal summary",
:description => "meal description",
:type => "Meal",
:menu => [],
:_attachments => { "meal#{i}.jpg" => {
:content_type => "image/gif"}


RestClient.put "#{@@db}/#{date.to_s}",
:content_type => 'application/json'

memo + [date.to_s]
The content is the base64 encoded content of good old 1x1 spacer.gif. It does not matter much what the content is for the purposes of the Cucumber scenario—just that the filename ends with "jpg" (implementation detail of the image_link helper). With images attached to each meal, I can verify this Cucumber step with:
Then /^the prominently displayed meals should include a thumbnail image$/ do
response.should have_selector("img", :count => 10)
That's a good stopping point for tonight. Tomorrow, I will mark off the meals-should-include-recipe-titles step as complete. I already have enough code to implement that step, but have a kink or two that needs working out before I consider it really done.

No comments:

Post a Comment