diff --git a/public/javascripts/app/models/post.js b/public/javascripts/app/models/post.js index a8ddf1c59..c7ad731c6 100644 --- a/public/javascripts/app/models/post.js +++ b/public/javascripts/app/models/post.js @@ -8,8 +8,8 @@ app.models.Post = Backbone.Model.extend({ setupCollections: function() { this.comments = new app.collections.Comments(this.get("comments") || this.get("last_three_comments"), {post : this}); - this.likes = new app.collections.Likes([], {post : this}); // load in the user like initially - this.participations = new app.collections.Participations([], {post : this}); // load in the user like initially + this.likes = this.likes || new app.collections.Likes([], {post : this}); // load in the user like initially + this.participations = this.participations || new app.collections.Participations([], {post : this}); // load in the user like initially }, createdAt : function() { diff --git a/public/javascripts/app/views/comment_stream_view.js b/public/javascripts/app/views/comment_stream_view.js index bcadbc317..5a11626f4 100644 --- a/public/javascripts/app/views/comment_stream_view.js +++ b/public/javascripts/app/views/comment_stream_view.js @@ -13,6 +13,8 @@ app.views.CommentStream = app.views.Base.extend({ initialize: function(options) { this.model.comments.bind('add', this.appendComment, this); this.commentTemplate = options.commentTemplate; + + this.model.bind("commentsExpanded", this.render, this) }, postRenderTemplate : function() { @@ -60,9 +62,12 @@ app.views.CommentStream = app.views.Base.extend({ var self = this; this.model.comments.fetch({ - success : function(){ - self.model.set({all_comments_loaded : true}); - self.render(); + success : function(resp){ + self.model.set({ + comments : resp.models, + all_comments_loaded : true + }) + self.model.trigger("commentsExpanded", self) } }); } diff --git a/public/javascripts/app/views/likes_info_view.js b/public/javascripts/app/views/likes_info_view.js index 5deac53ee..146f859a2 100644 --- a/public/javascripts/app/views/likes_info_view.js +++ b/public/javascripts/app/views/likes_info_view.js @@ -8,6 +8,10 @@ app.views.LikesInfo = app.views.StreamObject.extend({ tooltipSelector : ".avatar", + initialize : function() { + this.model.bind('expandedLikes', this.render, this) + }, + presenter : function() { return _.extend(this.defaultPresenter(), { likes : this.model.likes.models @@ -21,6 +25,7 @@ app.views.LikesInfo = app.views.StreamObject.extend({ .done(function(resp){ // set like attribute and like collection self.model.set({likes : self.model.likes.reset(resp)}) + self.model.trigger("expandedLikes") }) } }); diff --git a/spec/javascripts/app/views/comment_stream_view_spec.js b/spec/javascripts/app/views/comment_stream_view_spec.js index 6467e210f..3bff3494e 100644 --- a/spec/javascripts/app/views/comment_stream_view_spec.js +++ b/spec/javascripts/app/views/comment_stream_view_spec.js @@ -4,6 +4,14 @@ describe("app.views.CommentStream", function(){ loginAs({}) }) + 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() + }) + }) + describe("postRenderTemplate", function(){ it("applies infield labels", function(){ spyOn($.fn, "placeholder") diff --git a/spec/javascripts/app/views/likes_info_view_spec.js b/spec/javascripts/app/views/likes_info_view_spec.js index ec6a2e82d..b026da579 100644 --- a/spec/javascripts/app/views/likes_info_view_spec.js +++ b/spec/javascripts/app/views/likes_info_view_spec.js @@ -28,6 +28,12 @@ describe("app.views.LikesInfo", function(){ expect($(this.view.el).html().trim()).toBe(""); }) + + it("fires on a model change", function(){ + spyOn(this.view, "postRenderTemplate") + this.view.model.trigger('expandedLikes') + expect(this.view.postRenderTemplate).toHaveBeenCalled() + }) }) describe("showAvatars", function(){