Tuesday, April 28, 2009


‹prev | My Chain | next›

Up first in the sorting scenario are the creation of sortable, dummy recipes:
Given /^(\d+) "([^\"]*)" recipes with ascending names, dates, preparation times, and number of ingredients$/ do |count, keyword|
date = Date.new(2008, 4, 28)

(1..count.to_i).each do |i|
permalink = "id-#{i}-#{keyword.gsub(/\W/, '-')}"

recipe = {
:title => "#{keyword} recipe #{i}",
:date => date + i,
:prep_time => i,
:preparations =>
map {|j| { :ingredient => { :name => "ingredient #{j}"}} }

RestClient.put "#{@@db}/#{permalink}",
:content_type => 'application/json'
There are a few differences between this and the creation of the dummy records for pagination. The date for each recipe exploits date arithmetic by adding a day to each subsequent recipe. Similarly, each recipe has 1 more ingredient that its predecessor.

With that, there are 4 steps passing (3 were defined by other scenarios) and 6 skipped (also defined by other scenarios, but not reached). This leave 13 that need to be defined.

Before wading into the code, I think I will implement the next undefined step (clicking the search results header for sorting). Doing so will get my mind right for implementing examples:
When /^I click the "([^\"]*)" column header$/ do |link|
When clicking the "Name" column heading, for example, I expect to find it in an a tag with an id of "sort-by-name".

Unfortunately, when I start work on the view, I run into a problem implementing this example:
  it "should link to sort by date" do
assigns[:query] = "foo"
response.should have_selector("th > a",
:href => "/recipes/search?q=foo&sort=name",
:content => "name")
The error that occurs is:
cstrom@jaynestown:~/repos/eee-code$ spec ./spec/views/search.haml_spec.rb

'search.haml should link to sort by date' FAILED
expected following output to contain a <th > a href='/recipes/search?q=foo&sort=name'>name</th > a> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<a href="/recipes/search?q=foo&sort=name">Name</a>
Initially, I think the problem is that Haml is escaping the ampersand that is separating the query parameters. I am not expecting it to do so.

I spent a lot of time Googling to see how to prevent Haml from escaping the href attribute. Ultimately I was unsuccessful in that pursuit. What I did find was that it is apparently OK to escape them in query parameters. I knew about the semi-colon separators from my XML/XSL days, but being able to use &amp; is news to me. Something for #standup tomorrow!

Ultimately, this was not the problem. My mistake was that I was expecting lowercase "name" in the a tag, but am generating an upper case "Name". Once fixed, all specs pass for tonight.

Really could have used a pair to save me from wasting time tonight. Ah well, there's always tomorrow.

No comments:

Post a Comment