From 61d140faf4fc80382ee2e1126693e42e928343eb Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Sun, 30 Nov 2014 19:18:01 -0700 Subject: [PATCH] Added a test. #253 --- .../datastore/sync_methods/inject.test.js | 59 ++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/test/integration/datastore/sync_methods/inject.test.js b/test/integration/datastore/sync_methods/inject.test.js index 2434782..d9f1bb2 100644 --- a/test/integration/datastore/sync_methods/inject.test.js +++ b/test/integration/datastore/sync_methods/inject.test.js @@ -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); @@ -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); + }); });