Skip to content

Commit

Permalink
Added a test. #253
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Dec 1, 2014
1 parent 1e21413 commit 61d140f
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions test/integration/datastore/sync_methods/inject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ describe('DS.inject(resourceName, attrs[, options])', function () {

setTimeout(function () {
assert.deepEqual('Doh! You just changed the primary key of an object! ' +
'I don\'t know how to handle this yet, so your data for the "post' +
'" resource is now in an undefined (probably broken) state.', $log.error.logs[0][0]);
'I don\'t know how to handle this yet, so your data for the "post' +
'" resource is now in an undefined (probably broken) state.', $log.error.logs[0][0]);

done();
}, 50);
Expand Down Expand Up @@ -276,4 +276,59 @@ describe('DS.inject(resourceName, attrs[, options])', function () {
assert.isDefined(DS.get('foo', 6));
assert.isDefined(DS.get('foo', 7));
});
it('should work when injecting child relations multiple times', function () {
var Parent = DS.defineResource({
name: 'parent',
relations: {
hasMany: {
child: {
localField: 'children',
foreignKey: 'parentId'
}
}
}
});

var Child = DS.defineResource({
name: 'child',
relations: {
belongsTo: {
parent: {
localField: 'parent',
localKey: 'parentId'
}
}
}
});

Parent.inject({
id: 1,
name: 'parent1',
children: [{
id: 1,
name: 'child1'
}]
});

assert.isTrue(Parent.get(1).children[0] instanceof Child.Child);

Parent.inject({
id: 1,
name: 'parent',
children: [
{
id: 1,
name: 'Child-1'
},
{
id: 2,
name: 'Child-2'
}
]
});

assert.isTrue(Parent.get(1).children[0] instanceof Child.Child);
assert.isTrue(Parent.get(1).children[1] instanceof Child.Child);
assert.deepEqual(Child.filter({ parentId: 1 }), Parent.get(1).children);
});
});

0 comments on commit 61d140f

Please sign in to comment.