Skip to content

Commit

Permalink
Prominently display 10 meals on the homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
eee-c committed Jun 16, 2009
1 parent 8206f24 commit 6cca629
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 8 deletions.
17 changes: 15 additions & 2 deletions features/step_definitions/site.rb
Expand Up @@ -11,7 +11,11 @@
:summary => "meal summary",
:description => "meal description",
:type => "Meal",
:menu => []
:menu => [],
:_attachments => { "meal#{i}.jpg" => {
:data => "R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAEBMgA7",
:content_type => "image/gif"}
}
}

RestClient.put "#{@@db}/#{date.to_s}",
Expand Down Expand Up @@ -42,7 +46,7 @@
:content_type => 'application/json'

# Update the meal to include the recipe in the menu
meal['menu'] << "[recipe:#{permalink.gsub(/-/, '/')}"
meal['menu'] << "[recipe:#{permalink}]"
RestClient.put "#{@@db}/#{meal['_id']}",
meal.to_json,
:content_type => 'application/json'
Expand Down Expand Up @@ -88,3 +92,12 @@
response.should have_selector("h2", :content => "Meal 9")
response.should_not have_selector("h2", :content => "Meal 10")
end

Then /^the prominently displayed meals should include a thumbnail image$/ do
response.should have_selector("img", :count => 10)
end

Then /^the prominently displayed meals should include the recipe titles$/ do
response.should have_selector(".menu-items",
:content => "Recipe for Meal 1")
end
3 changes: 2 additions & 1 deletion helpers.rb
Expand Up @@ -37,7 +37,8 @@ def _db
self.class.send(:class_variable_get, "@@db")
end

def recipe_link(permalink, title=nil)
def recipe_link(link, title=nil)
permalink = link.gsub(/\//, '-')
recipe = JSON.parse(RestClient.get("#{_db}/#{permalink}"))
%Q|<a href="/recipes/#{recipe['_id']}">#{title || recipe['title']}</a>|
end
Expand Down
23 changes: 23 additions & 0 deletions spec/eee_helpers_spec.rb
Expand Up @@ -58,6 +58,29 @@
end
end

describe "recipe_link" do
before(:each) do
@json = '{"_id":"2009-06-11-recipe","title":"Recipe for Foo"}'
RestClient.
stub!(:get).
and_return(@json)
end
it "should link to recipe resource" do
recipe_link("2009-06-11-recipe").
should have_selector("a",
:href => "/recipes/2009-06-11-recipe")
end
it "should be able to link with \"slash\" dates (e.g. 2009/06/11/recipe)" do
RestClient.
should_receive(:get).
with(/2009-06-11-recipe/).
and_return(@json)

recipe_link("2009/06/11/recipe")
end
end


describe "image_link" do
context do
before(:each) do
Expand Down
34 changes: 30 additions & 4 deletions spec/views/index.haml_spec.rb
Expand Up @@ -2,10 +2,13 @@

describe "index.haml" do
before(:each) do
assigns[:meals] = [{ "id" => "2009-05-15",
"date" => "2009-05-15",
"title" => "Bar",
"summary" => "Bar summary"}]
assigns[:meals] = [{ "_id" => "2009-05-15",
"date" => "2009-05-15",
"title" => "Bar",
"summary" => "Bar summary",
"menu" => [],
"_attachments" => {"image1.jpg" => { }}
}]
end

it "should link to the meal titles" do
Expand All @@ -25,4 +28,27 @@
:content => "bar")

end

it "should include a thumbnail image of the meal" do
render("/views/index.haml")
response.should have_selector("img",
:src => "/images/2009-05-15/image1.jpg",
:width => "200",
:height => "150")
end

it "should include a comma separated list of menu items" do
assigns[:meals][0]["menu"] << "chips"
assigns[:meals][0]["menu"] << "salsa"
render("/views/index.haml")
response.should have_selector(".menu-items",
:content => "chips, salsa")
end

it "should wikify menu items" do
assigns[:meals][0]["menu"] << "_really_ hot salsa"
render("/views/index.haml")
response.should have_selector(".menu-items em",
:content => "really")
end
end
4 changes: 3 additions & 1 deletion views/index.haml
@@ -1,5 +1,7 @@
.meals
%h1 Meals
- @meals.each do |meal|
= image_link meal, :width => 200, :height => 150
%h2= meal["title"]
%p= wiki(meal["summary"])
= wiki(meal["summary"])
.menu-items= wiki(meal["menu"].join(", "))

0 comments on commit 6cca629

Please sign in to comment.