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})