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

a failing test for problem described in #146. No solution, yet. #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
60 changes: 60 additions & 0 deletions test/full.js
Original file line number Diff line number Diff line change
Expand Up @@ -1613,3 +1613,63 @@ test('#118 setOnce can be used with default string', function (t) {

t.end();
});

test('#146 consistently apply parse for children and collections', function (t) {
var Person = State.extend({
props: {
name: 'string',
parsed: {
type: 'number',
default: 0
}
},
// parse counts itself as parsed when ran
parse: function (attrs) {
if (typeof attrs.parsed !== 'number') {
attrs.parsed = 0;
}
attrs.parsed += 1;
return attrs;
}
});

var Friends = Collection.extend({
model: Person
});

var ParentObj = State.extend({
children: {
child: Person
},
collections: {
friends: Friends
}
});

var Parents = Collection.extend({
model: ParentObj
});

var parents = new Parents();

parents.add([
{
name: 'first',
child: {
name: 'mary'
},
friends: [
{
name: 'bob'
}
]
}
], {parse: true});

console.log(parents.at(0).friends.length);

t.equal(parents.at(0).child.parsed, 1, 'child should have been parsed');
t.equal(parents.at(0).friends.at(0).parsed, 1, 'friend collection items should have been parsed');

t.end();
});