Skip to content

Commit

Permalink
View specs and implementation for displaying tools and appliances use…
Browse files Browse the repository at this point in the history
…d in recipe preparation
  • Loading branch information
eee-c committed Apr 2, 2009
1 parent db9fecd commit 0318121
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions helpers.rb
Expand Up @@ -5,5 +5,9 @@ def hours(minutes)
m = minutes.to_i % 60
h > 0 ? "#{h} hours" : "#{m} minutes"
end

def amazon_url(asin)
"http://www.amazon.com/exec/obidos/ASIN/#{asin}/eeecooks-20"
end
end
end
35 changes: 35 additions & 0 deletions spec/views/recipe.haml_spec.rb
Expand Up @@ -11,6 +11,17 @@
response.should have_selector("h1", :content => @title)
end

context "a recipe with no tools or appliances" do
before(:each) do
@recipe[:tools] = nil
end

it "should not render an ingredient preparations" do
render("views/recipe.haml")
response.should_not have_selector(".eee-recipe-tools")
end
end

context "a recipe with no ingredient preparations" do
before(:each) do
@recipe[:preparations] = nil
Expand Down Expand Up @@ -157,4 +168,28 @@
response.should contain(/Inactive Time: 5 hours/)
end
end

context "a recipe requiring a colander and a pot" do
before(:each) do
colander = {
'title' => "Colander",
'asin' => "ASIN-1234"
}
pot = {
'title' => "Pot",
'asin' => "ASIN-5678"
}

@recipe['tools'] = [colander, pot]
render("views/recipe.haml")
end
it "should contain a link to the colander on Amazon" do
response.should have_selector("a", :content => "Colander",
:href => "http://www.amazon.com/exec/obidos/ASIN/ASIN-1234/eeecooks-20")
end
it "should contain a link to the pot on Amazon" do
response.should have_selector("a", :content => "Pot",
:href => "http://www.amazon.com/exec/obidos/ASIN/ASIN-5678/eeecooks-20")
end
end
end
8 changes: 8 additions & 0 deletions views/recipe.haml
Expand Up @@ -6,6 +6,14 @@
- if @recipe['inactive_time']
%div= "Inactive Time: " + hours(@recipe['inactive_time'])

- if @recipe['tools']
.eee-recipe-tools
%h2= "Tools and Appliances Used"
%ul
- @recipe['tools'].each do |tool|
%li
%a{:href => amazon_url(tool['asin'])}
= tool['title']

- if @recipe['preparations']
%ul.preparations
Expand Down

0 comments on commit 0318121

Please sign in to comment.