Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 1 #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions ampersand-collection.js
Expand Up @@ -38,8 +38,8 @@ assign(Collection.prototype, AmpersandEvents, {
// overridable serialize method
serialize: function () {
return this.map(function (model) {
if (model.serialize) {
return model.serialize();
if (model.toJSON) {
return model.toJSON();
} else {
var out = {};
assign(out, model);
Expand Down
32 changes: 32 additions & 0 deletions test/main.js
Expand Up @@ -522,3 +522,35 @@ test('Collection should rethrow change events on a model', function (t) {

model.name = 'shmoe';
});

test('Collection should call toJSON-func on a model during it\' own serialize-func', function (t) {
var MyChild = State.extend({
props: {
test1: ['boolean', true, true],
},
session: {
check: ['boolean', true, false],
},
toJSON: function () {
this.check = true;
return this.serialize();
}
});
var MyCollection = Collection.extend({
model: MyChild
});

var a = new MyCollection([{
test1: true
},{
test1: true
}]);
var json = a.toJSON();

t.equal(a.models[0].check, true);
t.equal(a.models[1].check, true);
t.deepEqual(json[0],a.models[0].serialize());
t.deepEqual(json[1],a.models[1].serialize());

t.end();
});