From cd965e32fa04e14e6bf48f45f82bcf17c342ea03 Mon Sep 17 00:00:00 2001 From: Florian Staudacher Date: Wed, 14 Mar 2012 18:43:06 +0100 Subject: [PATCH] fix comment stream jasmine - bind function after spy has been defined --- public/javascripts/app/views/comment_stream_view.js | 6 +++++- spec/javascripts/app/views/comment_stream_view_spec.js | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/public/javascripts/app/views/comment_stream_view.js b/public/javascripts/app/views/comment_stream_view.js index 5a11626f4..5ab537e74 100644 --- a/public/javascripts/app/views/comment_stream_view.js +++ b/public/javascripts/app/views/comment_stream_view.js @@ -14,7 +14,11 @@ app.views.CommentStream = app.views.Base.extend({ this.model.comments.bind('add', this.appendComment, this); this.commentTemplate = options.commentTemplate; - this.model.bind("commentsExpanded", this.render, this) + this.setupBindings(); + }, + + setupBindings: function() { + this.model.bind("commentsExpanded", this.render, this); }, postRenderTemplate : function() { diff --git a/spec/javascripts/app/views/comment_stream_view_spec.js b/spec/javascripts/app/views/comment_stream_view_spec.js index 3bff3494e..343a7d246 100644 --- a/spec/javascripts/app/views/comment_stream_view_spec.js +++ b/spec/javascripts/app/views/comment_stream_view_spec.js @@ -6,9 +6,10 @@ describe("app.views.CommentStream", function(){ describe("binds", function() { it("re-renders on a commentsExpanded trigger", function(){ - spyOn(this.view, "render") - this.view.model.trigger("commentsExpanded") - expect(this.view.render).toHaveBeenCalled() + spyOn(this.view, "render"); + this.view.setupBindings(); + this.view.model.trigger("commentsExpanded"); + expect(this.view.render).toHaveBeenCalled(); }) })