Permalink
Browse files

RecipeListView and spec

  • Loading branch information...
1 parent 7fdbc27 commit 6c3d5ae36fa637c5b182af5098e539b28afa2372 @dougalcorn dougalcorn committed with Nov 1, 2011
@@ -0,0 +1,4 @@
+class Cookbook.RecipeListView extends Backbone.View
+
+ render: ->
+ @el.html JST["recipe_list_view_template"] @
@@ -0,0 +1,5 @@
+<ul>
+<% for model in @collection.models: %>
+<li><a href="#recipes/<%= model.get('id') %>"><%= model.get('title') %></a></li>
+<% end %>
+</ul>
@@ -0,0 +1,17 @@
+describe "RecipeListView", ->
+ beforeEach ->
+ @collection = new Cookbook.Recipes [
+ {id: 1, title: "pancakes", description: "I like pancakes"}
+ {id: 2, title: "flapjacks", description: "A worthy substitute for pancakes"}
+ {id: 3, title: "potato cakes", description: "Deliciously fried"}
+ ]
+ setFixtures("<div id='recipe-list-view'></div>")
+ @listView = new Cookbook.RecipeListView(el: $('#recipe-list-view'), collection: @collection)
+
+ describe "render", ->
+ beforeEach ->
+ @listView.render()
+ it "displays a list item for each recipe", ->
+ expect($('#recipe-list-view ul li').size()).toEqual(3)
+ it "links to show each recipe", ->
+ expect($("a[href='#recipes/1']")).toExist()

0 comments on commit 6c3d5ae

Please sign in to comment.