Before moving onto the next Cucumber scenario, I take a moment to see if the previous scenario missed anything. I think it likely covered just about all of the necessary behavior needed. But the legacy Rails site (and the previous incarnation as an XML-based CMS) built up many affordances that I would prefer not to lose in translation.
The homepage in Webrat
save_and_open_page
form:The homepage on the legacy Rails site:
Naked CSS and missing images aside, it looks as though I am missing:
- The date of the meals
- A "Read more..." link for the meal
- Only linking to new recipes, not the entire menu
- Meals on odd numbered days have right-aligned thumbnails (added "depth")
- Text links to older meals at the bottom of the meals section
it "should include a pretty date for each meal" doThis can be implemented with:
render("/views/index.haml")
response.should have_selector(".meals", :content => "May 15")
end
%div= date.strftime("%B %e")The next affordance to be added is:
it "should suggest that the user read more..." doA simple link will make that example pass.
render("/views/index.haml")
response.should have_selector(".meals a",
:href => "/meals/2009/05/15",
:content => "Read more…")
end
Only including new recipes rather than the whole meal menu is a bit trickier. The examples require building up the menu, which makes for longer examples.
One or more new recipes (the meal was prepared on 2009-05-15, new recipes would be from the same day) should be comma separated:
it "should include a comma separated list of menu items" doOld recipes and non-recipes should not be included on the homepage:
stub!(:recipe_link).
and_return(%Q|<a href="/recipes/2009/05/15/recipe1">chips</a>|,
%Q|<a href="/recipes/2009/05/15/recipe2">salsa</a>|)
assigns[:meals][0]["menu"] << "[recipe:2009/05/15/recipe1]"
assigns[:meals][0]["menu"] << "[recipe:2009/05/15/recipe2]"
render("/views/index.haml")
response.should have_selector(".menu-items",
:content => "chips, salsa")
end
it "should only include new recipe menu items" doNo new recipes should produce nothing:
stub!(:recipe_link).
and_return(%Q|<a href="/recipes/2009/05/15/recipe1">chips</a>|)
assigns[:meals][0]["menu"] << "[recipe:2009/05/14/recipe1]"
assigns[:meals][0]["menu"] << "chili"
assigns[:meals][0]["menu"] << "[recipe:2009/05/15/recipe2]"
render("/views/index.haml")
response.should have_selector(".menu-items",
:content => "chips")
end
it "should not include a delimiter between \"Read more\" and new recipes when no new recipes" doI implement these three examples with this Haml code:
render("/views/index.haml")
response.should_not have_selector(".meals",
:content => "|")
end
- new_recipe_regexp = Regexp.new(date.strftime("%Y/%m/%d"))In that code snippet, I store a regular expression built from the meal's current date. I use that regular expression to select all recipes from the menu that match the current date. As long as there are new recipes, a "pipe" delimiter is inserted between the link to the current meal and to the new recipes. Finally, the
- new_recipes = meal["menu"].select{ |r| r =~ new_recipe_regexp }
(
%a{:href => date.strftime("/meals/%Y/%m/%d")}
Read more…
- if new_recipes.length > 0
|
.menu-items= wiki(new_recipes.join(", "))
)
wiki
helper converts the wiki recipe text to HTML links.I will stop there for today and pick up with the last two missing affordances tomorrow.
No comments:
Post a Comment