From 4a755e259f2ca12b8dd3d7c9ba4c479b6d8206fd Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Thu, 6 Aug 2015 14:55:50 -0700 Subject: [PATCH] [Entanglement] Link service returns object in new context The link service return the object in the new context. --- .../entanglement/src/services/LinkService.js | 11 ++++++++ .../test/services/LinkServiceSpec.js | 8 +++++- .../test/services/MockLinkService.js | 27 ++++++------------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/platform/entanglement/src/services/LinkService.js b/platform/entanglement/src/services/LinkService.js index acecab3b8d..da9a2f92da 100644 --- a/platform/entanglement/src/services/LinkService.js +++ b/platform/entanglement/src/services/LinkService.js @@ -66,6 +66,17 @@ define( } }).then(function () { return parentObject.getCapability('persistence').persist(); + }).then(function getObjectWithNewContext() { + return parentObject + .useCapability('composition') + .then(function (children) { + var i; + for (i = 0; i < children.length; i += 1) { + if (children[i].getId() === object.getId()) { + return children[i]; + } + } + }); }); } }; diff --git a/platform/entanglement/test/services/LinkServiceSpec.js b/platform/entanglement/test/services/LinkServiceSpec.js index 0551256277..80094db519 100644 --- a/platform/entanglement/test/services/LinkServiceSpec.js +++ b/platform/entanglement/test/services/LinkServiceSpec.js @@ -25,7 +25,8 @@ define( [ '../../src/services/LinkService', - '../DomainObjectFactory' + '../DomainObjectFactory', + '../ControlledPromise' ], function (LinkService, domainObjectFactory) { "use strict"; @@ -177,6 +178,11 @@ define( expect(persistenceCapability.persist).toHaveBeenCalled(); }); + + it("returns object representing new link", function () { + linkService.perform(object, parentObject); + + }); }); }); } diff --git a/platform/entanglement/test/services/MockLinkService.js b/platform/entanglement/test/services/MockLinkService.js index 58a82333d3..d4b25b566f 100644 --- a/platform/entanglement/test/services/MockLinkService.js +++ b/platform/entanglement/test/services/MockLinkService.js @@ -23,7 +23,10 @@ /*global define,jasmine */ define( - function () { + [ + '../ControlledPromise' + ], + function (ControlledPromise) { "use strict"; /** @@ -67,26 +70,12 @@ define( callExtensions, spy; - performPromise = jasmine.createSpyObj( - 'performPromise', - ['then'] - ); + performPromise = new ControlledPromise(); - callExtensions = { - promise: performPromise, - resolve: function (resolveWith) { - performPromise.then.calls.forEach(function (call) { - call.args[0](resolveWith); - }); - } - }; + this.perform.mostRecentCall.promise = performPromise; + this.perform.calls[this.perform.calls.length - 1].promise = + performPromise; - spy = this.perform; - - Object.keys(callExtensions).forEach(function (key) { - spy.mostRecentCall[key] = callExtensions[key]; - spy.calls[spy.calls.length - 1][key] = callExtensions[key]; - }); return performPromise; });