From b0a8425617034264aba8f0393d9fb03c63e349d8 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 13 May 2011 10:22:13 -0400 Subject: [PATCH] more fixes --- templates/collection_view.coffee.erb | 3 ++- templates/collection_view_spec.coffee.erb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/templates/collection_view.coffee.erb b/templates/collection_view.coffee.erb index a99b2a9..b08e762 100644 --- a/templates/collection_view.coffee.erb +++ b/templates/collection_view.coffee.erb @@ -7,12 +7,13 @@ class window.<%= plural_object_name %>View extends Backbone.View @collection.bind('refresh', this.addAll) render: => $(this.el).html(this.template()) + this.addAll() this addOne: (model) => view = new <%= object_name %>View({model: model}) this.$('.list').append(view.render().el) addAll: => - @collection.each(this.addOne()) + @collection.each(this.addOne) addNew: => facility = new <%= object_name %>() @collection.add(facility) diff --git a/templates/collection_view_spec.coffee.erb b/templates/collection_view_spec.coffee.erb index cd045bd..dc36669 100644 --- a/templates/collection_view_spec.coffee.erb +++ b/templates/collection_view_spec.coffee.erb @@ -16,3 +16,11 @@ describe '<%= plural_object_name %>View', -> expect(view.$('.list')).toContain('.<%= css_class_name %>') expect(collection.length).toEqual(1) + it 'should render the models when re-rendered', -> + expect(view.$('.list')).not.toContain('.<%= css_class_name %>') + + model = new <%= object_name %>({id: 1}) + collection.add(model) + view.render() + + expect(view.$('.list')).toContain('.<%= css_class_name %>')