Skip to content
This repository has been archived by the owner on May 17, 2018. It is now read-only.

Commit

Permalink
Fix #112 models now parsed correctly when passed via constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
wyuenho committed Nov 1, 2013
1 parent 8165451 commit d0c0db4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
5 changes: 2 additions & 3 deletions lib/backbone-pageable.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@

var PARAM_TRIM_RE = /[\s'"]/g;
var URL_TRIM_RE = /[<>\s'"]/g;
var BaseCollection = Backbone.Collection;

/**
Drop-in replacement for Backbone.Collection. Supports server-side and
Expand Down Expand Up @@ -257,7 +256,7 @@
*/
constructor: function (models, options) {

BaseCollection.apply(this, arguments);
BBColProto.constructor.apply(this, arguments);

options = options || {};

Expand Down Expand Up @@ -685,7 +684,7 @@
var fullCollection = this.fullCollection;
var handlers = this._handlers = this._handlers || {}, handler;
if (mode != "server" && !fullCollection) {
fullCollection = this._makeFullCollection(options.models || []);
fullCollection = this._makeFullCollection(options.models || [], options);
fullCollection.pageableCollection = this;
this.fullCollection = fullCollection;
var allHandler = this._makeCollectionEventHandler(this, fullCollection);
Expand Down
29 changes: 25 additions & 4 deletions test/client-pageable.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ $(document).ready(function () {
strictEqual(col.comparator, comparator);
strictEqual(col.size(), 2);
strictEqual(col.at(0).get("name"), "a");
strictEqual(col.at(1).get("name"), "c");
strictEqual(col.at(1).get("name"), "b");
strictEqual(col.fullCollection.size(), 3);
strictEqual(col.at(0), col.fullCollection.at(0));
strictEqual(col.fullCollection.at(0).get("name"), "a");
strictEqual(col.fullCollection.at(1).get("name"), "c");
strictEqual(col.fullCollection.at(2).get("name"), "b");
strictEqual(col.fullCollection.at(1).get("name"), "b");
strictEqual(col.fullCollection.at(2).get("name"), "c");

mods = models.slice();

Expand Down Expand Up @@ -556,7 +556,7 @@ $(document).ready(function () {
strictEqual(col.fullCollection.at(2).get("name"), "b");
strictEqual(col.fullCollection.at(3).get("name"), "a");
});

test("getPageByOffset - firstPage is 0", function () {
var manyModels = [
{"name": "a1"},
Expand Down Expand Up @@ -808,4 +808,25 @@ $(document).ready(function () {
strictEqual(col.hasNext(), false);
});

test("parsing from constructor #112", function () {
var Model = Backbone.Model.extend({
parse: function (raw) {
return { value: raw }
}
});

var MyCollection = Backbone.PageableCollection.extend({
model: Model,
mode: 'client',
state: {
firstPage: 0,
pageSize: 2
}
});

var col = new MyCollection([1, 2, 3], {parse: true});
deepEqual(col.toJSON(), [{"value": 1}, {"value": 2}]);
deepEqual(col.fullCollection.toJSON(), [{"value": 1}, {"value": 2}, {"value": 3}]);
});

});

0 comments on commit d0c0db4

Please sign in to comment.