Skip to content

Commit 61d140f

Browse files
committed
Added a test. #253
1 parent 1e21413 commit 61d140f

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

test/integration/datastore/sync_methods/inject.test.js

+57-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ describe('DS.inject(resourceName, attrs[, options])', function () {
4646

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

5252
done();
5353
}, 50);
@@ -276,4 +276,59 @@ describe('DS.inject(resourceName, attrs[, options])', function () {
276276
assert.isDefined(DS.get('foo', 6));
277277
assert.isDefined(DS.get('foo', 7));
278278
});
279+
it('should work when injecting child relations multiple times', function () {
280+
var Parent = DS.defineResource({
281+
name: 'parent',
282+
relations: {
283+
hasMany: {
284+
child: {
285+
localField: 'children',
286+
foreignKey: 'parentId'
287+
}
288+
}
289+
}
290+
});
291+
292+
var Child = DS.defineResource({
293+
name: 'child',
294+
relations: {
295+
belongsTo: {
296+
parent: {
297+
localField: 'parent',
298+
localKey: 'parentId'
299+
}
300+
}
301+
}
302+
});
303+
304+
Parent.inject({
305+
id: 1,
306+
name: 'parent1',
307+
children: [{
308+
id: 1,
309+
name: 'child1'
310+
}]
311+
});
312+
313+
assert.isTrue(Parent.get(1).children[0] instanceof Child.Child);
314+
315+
Parent.inject({
316+
id: 1,
317+
name: 'parent',
318+
children: [
319+
{
320+
id: 1,
321+
name: 'Child-1'
322+
},
323+
{
324+
id: 2,
325+
name: 'Child-2'
326+
}
327+
]
328+
});
329+
330+
assert.isTrue(Parent.get(1).children[0] instanceof Child.Child);
331+
assert.isTrue(Parent.get(1).children[1] instanceof Child.Child);
332+
assert.deepEqual(Child.filter({ parentId: 1 }), Parent.get(1).children);
333+
});
279334
});

0 commit comments

Comments
 (0)