more fixes

This commit is contained in:
John Bintz 2011-05-13 10:22:13 -04:00
parent 6b31491da7
commit b0a8425617
2 changed files with 10 additions and 1 deletions

View File

@ -7,12 +7,13 @@ class window.<%= plural_object_name %>View extends Backbone.View
@collection.bind('refresh', this.addAll) @collection.bind('refresh', this.addAll)
render: => render: =>
$(this.el).html(this.template()) $(this.el).html(this.template())
this.addAll()
this this
addOne: (model) => addOne: (model) =>
view = new <%= object_name %>View({model: model}) view = new <%= object_name %>View({model: model})
this.$('.list').append(view.render().el) this.$('.list').append(view.render().el)
addAll: => addAll: =>
@collection.each(this.addOne()) @collection.each(this.addOne)
addNew: => addNew: =>
facility = new <%= object_name %>() facility = new <%= object_name %>()
@collection.add(facility) @collection.add(facility)

View File

@ -16,3 +16,11 @@ describe '<%= plural_object_name %>View', ->
expect(view.$('.list')).toContain('.<%= css_class_name %>') expect(view.$('.list')).toContain('.<%= css_class_name %>')
expect(collection.length).toEqual(1) 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 %>')