From 09a840ea418b0a3e567a495da79abdf3f87f748c Mon Sep 17 00:00:00 2001 From: Florian Staudacher Date: Sun, 26 Jan 2014 19:51:12 +0100 Subject: [PATCH] fix regression caused by updating backbone.js without updating changed parameters --- app/assets/javascripts/app/models/stream.js | 13 ++++++--- .../javascripts/app/models/stream_aspects.js | 7 ++--- .../app/models/stream_aspects_spec.js | 28 +++++++++++++++++++ 3 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 spec/javascripts/app/models/stream_aspects_spec.js diff --git a/app/assets/javascripts/app/models/stream.js b/app/assets/javascripts/app/models/stream.js index f417016fc..4cf5ff737 100644 --- a/app/assets/javascripts/app/models/stream.js +++ b/app/assets/javascripts/app/models/stream.js @@ -15,13 +15,18 @@ app.models.Stream = Backbone.Collection.extend({ return _.any(this.items.models) ? this.timeFilteredPath() : this.basePath() }, + _fetchOpts: function(opts) { + var defaultOpts = { + remove: false // tell backbone to keep existing items in the collection + }; + return _.extend({}, defaultOpts, opts); + }, + fetch: function() { if( this.isFetching() ) return false; var url = this.url(); - this.deferred = this.items.fetch({ - remove : false, - url : url - }).done(_.bind(this.triggerFetchedEvents, this)) + this.deferred = this.items.fetch(this._fetchOpts({url : url})) + .done(_.bind(this.triggerFetchedEvents, this)); }, isFetching : function() { diff --git a/app/assets/javascripts/app/models/stream_aspects.js b/app/assets/javascripts/app/models/stream_aspects.js index f8536c65d..4dc97899e 100644 --- a/app/assets/javascripts/app/models/stream_aspects.js +++ b/app/assets/javascripts/app/models/stream_aspects.js @@ -18,10 +18,7 @@ app.models.StreamAspects = app.models.Stream.extend({ if(this.isFetching()){ return false } var url = this.url(); var ids = this.aspects_ids; - this.deferred = this.items.fetch({ - add : true, - url : url, - data : { 'a_ids': ids } - }).done(_.bind(this.triggerFetchedEvents, this)) + this.deferred = this.items.fetch(this._fetchOpts({url : url, data : { 'a_ids': ids }})) + .done(_.bind(this.triggerFetchedEvents, this)); } }); diff --git a/spec/javascripts/app/models/stream_aspects_spec.js b/spec/javascripts/app/models/stream_aspects_spec.js new file mode 100644 index 000000000..f6d99195c --- /dev/null +++ b/spec/javascripts/app/models/stream_aspects_spec.js @@ -0,0 +1,28 @@ +describe("app.models.StreamAspects", function() { + describe("#fetch", function(){ + var fetch, + stream; + + beforeEach(function(){ + fetch = new $.Deferred(); + stream = new app.models.StreamAspects([], {aspects_ids: [1,2]}); + spyOn(stream.items, "fetch").andCallFake(function(options){ + stream.items.set([{name: 'a'}, {name: 'b'}, {name: 'c'}], options); + fetch.resolve(); + return fetch; + }); + }); + + it("fetches some posts", function(){ + stream.fetch(); + expect(stream.items.length).toEqual(3); + }); + + it("fetches more posts", function(){ + stream.fetch(); + expect(stream.items.length).toEqual(3); + stream.fetch(); + expect(stream.items.length).toEqual(6); + }); + }); +});