From 9cf30f42134d483f491b6f1dd190c86a573352fd Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Wed, 19 Aug 2015 11:15:09 -0700 Subject: [PATCH] [Location] setPrimaryLocation takes location. Rename "persistLocation" to be more clearly named, and make it take an argument to allow for greater control outside the capability. --- .../src/capabilities/LocationCapability.js | 12 ++++++++---- .../entanglement/src/services/MoveService.js | 18 +++++++++++++----- .../capabilities/LocationCapabilitySpec.js | 3 ++- .../test/services/MoveServiceSpec.js | 9 +++++---- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/platform/entanglement/src/capabilities/LocationCapability.js b/platform/entanglement/src/capabilities/LocationCapability.js index 7336d5f852..c55d15787d 100644 --- a/platform/entanglement/src/capabilities/LocationCapability.js +++ b/platform/entanglement/src/capabilities/LocationCapability.js @@ -18,15 +18,19 @@ define( } /** - * Persist the current location of the current domain object as it's - * primary location. Returns a promise. + * Set the primary location (the parent id) of the current domain + * object. + * + * @param {String} location the primary location to persist. + * @returns {Promise} a promise that is resolved when the operation + * completes. */ - LocationCapability.prototype.persistLocation = function () { + LocationCapability.prototype.setPrimaryLocation = function (location) { var capability = this; return this.domainObject.useCapability( 'mutation', function (model) { - model.location = capability.getLocation(); + model.location = location; } ).then(function () { return capability.domainObject diff --git a/platform/entanglement/src/services/MoveService.js b/platform/entanglement/src/services/MoveService.js index 7ee5876e4a..c5406f93c6 100644 --- a/platform/entanglement/src/services/MoveService.js +++ b/platform/entanglement/src/services/MoveService.js @@ -70,13 +70,21 @@ define( return linkService .perform(object, parentObject) .then(function (objectInNewContext) { - if (!object.hasCapability('location')) { + var newLocationCapability = objectInNewContext + .getCapability('location'), + oldLocationCapability = object + .getCapability('location'); + if (!newLocationCapability || + oldLocationCapability) { + return; } - if (object.getCapability('location').isOriginal()) { - return objectInNewContext - .getCapability('location') - .persistLocation(); + + + if (oldLocationCapability.isOriginal()) { + return newLocationCapability.setPrimaryLocation( + newLocationCapability.getLocation() + ); } }) .then(function () { diff --git a/platform/entanglement/test/capabilities/LocationCapabilitySpec.js b/platform/entanglement/test/capabilities/LocationCapabilitySpec.js index 83f166cbec..8c96500a8a 100644 --- a/platform/entanglement/test/capabilities/LocationCapabilitySpec.js +++ b/platform/entanglement/test/capabilities/LocationCapabilitySpec.js @@ -70,7 +70,8 @@ define( }); it("can persist location", function () { - var persistResult = locationCapability.persistLocation(), + var persistResult = locationCapability + .setPrimaryLocation('root'), whenComplete = jasmine.createSpy('whenComplete'); persistResult.then(whenComplete); diff --git a/platform/entanglement/test/services/MoveServiceSpec.js b/platform/entanglement/test/services/MoveServiceSpec.js index b48dd4e66e..fed7878ac7 100644 --- a/platform/entanglement/test/services/MoveServiceSpec.js +++ b/platform/entanglement/test/services/MoveServiceSpec.js @@ -162,12 +162,13 @@ define( 'locationCapability', [ 'isOriginal', - 'persistLocation' + 'setPrimaryLocation' ] ); locationPromise = new ControlledPromise(); - locationCapability.persistLocation.andReturn(locationPromise); + locationCapability.setPrimaryLocation + .andReturn(locationPromise); object = domainObjectFactory({ name: 'object', @@ -199,7 +200,7 @@ define( }); it("updates location", function () { - expect(locationCapability.persistLocation) + expect(locationCapability.setPrimaryLocation) .toHaveBeenCalled(); }); @@ -223,7 +224,7 @@ define( }); it("does not update location", function () { - expect(locationCapability.persistLocation) + expect(locationCapability.setPrimaryLocation) .not .toHaveBeenCalled(); });