diff --git a/app/assets/javascripts/app/pages/stream.js b/app/assets/javascripts/app/pages/stream.js index 99c2df8b4..7dec17e8e 100644 --- a/app/assets/javascripts/app/pages/stream.js +++ b/app/assets/javascripts/app/pages/stream.js @@ -22,7 +22,7 @@ app.pages.Stream = app.views.Base.extend({ this.streamView = new app.views.NewStream({ model : this.stream }) var interactions = this.interactionsView = new app.views.StreamInteractions() - this.on("frame:interacted", function(post){ + this.stream.on("frame:interacted", function(post){ interactions.setInteractions(post) }) } diff --git a/app/assets/javascripts/app/views.js b/app/assets/javascripts/app/views.js index dabedf1dd..3c57752ec 100644 --- a/app/assets/javascripts/app/views.js +++ b/app/assets/javascripts/app/views.js @@ -122,7 +122,7 @@ app.views.InfScroll = app.views.Base.extend({ }, createPostView : function(post){ - var postView = new this.postClass({ model: post }); + var postView = new this.postClass({ model: post, stream: this.stream }); this.postViews.push(postView) return postView }, diff --git a/app/assets/javascripts/app/views/post/small_frame.js b/app/assets/javascripts/app/views/post/small_frame.js index 976b2cfdd..ae79a1cb3 100644 --- a/app/assets/javascripts/app/views/post/small_frame.js +++ b/app/assets/javascripts/app/views/post/small_frame.js @@ -13,6 +13,11 @@ app.views.Post.SmallFrame = app.views.Post.extend({ '.embed-frame' : "oEmbedView" }, + initialize : function(options) { + this.stream = options.stream; + this.addStylingClasses() + }, + oEmbedView : function(){ return new app.views.OEmbed({model : this.model}) }, @@ -28,10 +33,6 @@ app.views.Post.SmallFrame = app.views.Post.extend({ }) }, - initialize : function() { - this.addStylingClasses() - }, - postRenderTemplate : function() { this.addStylingClasses() }, diff --git a/app/assets/javascripts/app/views/post/stream_frame.js b/app/assets/javascripts/app/views/post/stream_frame.js index ae98d3ebe..e80ac0df3 100644 --- a/app/assets/javascripts/app/views/post/stream_frame.js +++ b/app/assets/javascripts/app/views/post/stream_frame.js @@ -1,5 +1,4 @@ app.views.Post.StreamFrame = app.views.Base.extend({ - className : "stream-frame", templateName : "stream-frame", @@ -8,18 +7,19 @@ app.views.Post.StreamFrame = app.views.Base.extend({ ".small-frame" : "smallFrameView" }, - initialize : function() { - this.smallFrameView = new app.views.Post.SmallFrame({model : this.model}) + initialize : function(options) { + this.stream = options.stream + this.smallFrameView = new app.views.Post.SmallFrame({model : this.model, stream: this.stream}) }, events : _.extend({ 'click .content' : 'triggerInteracted' }, app.views.Post.SmallFrame.prototype.events), + triggerInteracted : function() { - app.page.trigger("frame:interacted", this.model) + this.stream.trigger("frame:interacted", this.model) }, - // this is some gross shit. goToPost : $.noop -}); \ No newline at end of file +}); diff --git a/app/assets/javascripts/app/views/post/stream_interactions_view.js b/app/assets/javascripts/app/views/post/stream_interactions_view.js index 8bff9c8f6..657f80d1f 100644 --- a/app/assets/javascripts/app/views/post/stream_interactions_view.js +++ b/app/assets/javascripts/app/views/post/stream_interactions_view.js @@ -1,5 +1,4 @@ app.views.StreamInteractions = app.views.Base.extend({ - id : "post-info", subviews:{ @@ -19,9 +18,5 @@ app.views.StreamInteractions = app.views.Base.extend({ this.feedback = new app.views.FeedbackActions({ model: model }) this.comments = new app.views.PostViewerReactions({ model: model.interactions }) this.newCommentView = new app.views.PostViewerNewComment({ model : model }) - }, - - postRenderTemplate : function(){ - console.log(this.$el) } }); diff --git a/spec/javascripts/app/pages/stream_spec.js b/spec/javascripts/app/pages/stream_spec.js new file mode 100644 index 000000000..346d550e0 --- /dev/null +++ b/spec/javascripts/app/pages/stream_spec.js @@ -0,0 +1,22 @@ +describe("app.Pages.Stream", function(){ + beforeEach(function(){ + app.setPreload("stream", [factory.post().attributes]) + this.page = new app.pages.Stream() + this.post = this.page.model.items.models[0] + expect(this.post).toBeTruthy() + }) + + describe("rendering", function(){ + beforeEach(function(){ + this.page.render() + }) + + context("clicking the content", function(){ + it("triggers frame interacted", function(){ + spyOn(this.post.interactions, "fetch").andReturn(new $.Deferred) + this.page.$('.canvas-frame:first .content').click() + expect(this.post.interactions.fetch).toHaveBeenCalled() + }) + }) + }) +}); \ No newline at end of file diff --git a/spec/javascripts/app/views/post/stream_frame_spec.js b/spec/javascripts/app/views/post/stream_frame_spec.js index 9d8c00776..ba526fc52 100644 --- a/spec/javascripts/app/views/post/stream_frame_spec.js +++ b/spec/javascripts/app/views/post/stream_frame_spec.js @@ -1,18 +1,23 @@ describe("app.views.Post.StreamFrame", function(){ beforeEach(function(){ this.post = factory.post() - this.view = new app.views.Post.StreamFrame({model : this.post}) - app.page = new app.pages.Stream({model : new app.models.Stream()}) + this.stream = new Backbone.Model + this.view = new app.views.Post.StreamFrame({model : this.post, stream: this.stream }) }) describe("rendering", function(){ + beforeEach(function(){ + this.view.render() + }) + context("clicking the content", function(){ - it("fetches the interaction pane", function(){ - spyOn(this.post.interactions, "fetch").andReturn(new $.Deferred) - this.view.render() + it("triggers frame interacted", function(){ + var spy = jasmine.createSpy() + this.stream.on("frame:interacted", spy) this.view.$('.content').click() - expect(this.post.interactions.fetch).toHaveBeenCalled() + expect(spy).toHaveBeenCalledWith(this.post) }) + }) }) }); \ No newline at end of file