From c9c7cff47900fc7618f60cfabe95dd8e596c26a8 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Sat, 7 Jan 2012 19:59:33 -0800 Subject: [PATCH] don't fetch more posts from the stream if only one post has been returned --- public/javascripts/app/views/stream_view.js | 2 +- .../javascripts/app/views/stream_view_spec.js | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/public/javascripts/app/views/stream_view.js b/public/javascripts/app/views/stream_view.js index 43b887b8c..451fd0e6b 100644 --- a/public/javascripts/app/views/stream_view.js +++ b/public/javascripts/app/views/stream_view.js @@ -58,7 +58,7 @@ app.views.Stream = Backbone.View.extend({ collectionFetched: function(collection, response) { this.$("#paginate").remove(); - if(collection.parse(response).length == 0) { + if(!collection.parse(response).length || collection.parse(response).length == 0) { this.allContentLoaded = true; $(window).unbind('scroll') return diff --git a/spec/javascripts/app/views/stream_view_spec.js b/spec/javascripts/app/views/stream_view_spec.js index a7df063f5..b867a090c 100644 --- a/spec/javascripts/app/views/stream_view_spec.js +++ b/spec/javascripts/app/views/stream_view_spec.js @@ -87,18 +87,28 @@ describe("app.views.Stream", function(){ }) describe("collectionFetched", function(){ + context("unbinding scroll", function(){ + beforeEach(function(){ + spyOn($.fn, "unbind") + }) + + it("unbinds scroll if there are no more posts left to load", function(){ + this.view.collectionFetched(this.collection, {posts : []}) + expect($.fn.unbind).toHaveBeenCalled() + }) + + it("does not fetch new content when the user is fetching one post", function(){ + this.view.collectionFetched(this.collection, {posts : {}}) + expect($.fn.unbind).toHaveBeenCalled() + }) + }) + it("sets this.allContentLoaded if there are no more posts left to load", function(){ expect(this.view.allContentLoaded).toBe(false) this.view.collectionFetched(this.collection, {posts : []}) expect(this.view.allContentLoaded).toBe(true) }) - it("unbinds scroll if there are no more posts left to load", function(){ - spyOn($.fn, "unbind") - this.view.collectionFetched(this.collection, {posts : []}) - expect($.fn.unbind).toHaveBeenCalled() - }) - it("does not set this.allContentLoaded if there was a non-empty response from the server", function(){ expect(this.view.allContentLoaded).toBe(false) this.view.collectionFetched(this.collection, {posts : this.posts})