[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.
This commit is contained in:
Pete Richards
2015-08-19 11:15:09 -07:00
parent eb776e69c0
commit 9cf30f4213
4 changed files with 28 additions and 14 deletions

View File

@@ -18,15 +18,19 @@ define(
} }
/** /**
* Persist the current location of the current domain object as it's * Set the primary location (the parent id) of the current domain
* primary location. Returns a promise. * 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; var capability = this;
return this.domainObject.useCapability( return this.domainObject.useCapability(
'mutation', 'mutation',
function (model) { function (model) {
model.location = capability.getLocation(); model.location = location;
} }
).then(function () { ).then(function () {
return capability.domainObject return capability.domainObject

View File

@@ -70,13 +70,21 @@ define(
return linkService return linkService
.perform(object, parentObject) .perform(object, parentObject)
.then(function (objectInNewContext) { .then(function (objectInNewContext) {
if (!object.hasCapability('location')) { var newLocationCapability = objectInNewContext
.getCapability('location'),
oldLocationCapability = object
.getCapability('location');
if (!newLocationCapability ||
oldLocationCapability) {
return; return;
} }
if (object.getCapability('location').isOriginal()) {
return objectInNewContext
.getCapability('location') if (oldLocationCapability.isOriginal()) {
.persistLocation(); return newLocationCapability.setPrimaryLocation(
newLocationCapability.getLocation()
);
} }
}) })
.then(function () { .then(function () {

View File

@@ -70,7 +70,8 @@ define(
}); });
it("can persist location", function () { it("can persist location", function () {
var persistResult = locationCapability.persistLocation(), var persistResult = locationCapability
.setPrimaryLocation('root'),
whenComplete = jasmine.createSpy('whenComplete'); whenComplete = jasmine.createSpy('whenComplete');
persistResult.then(whenComplete); persistResult.then(whenComplete);

View File

@@ -162,12 +162,13 @@ define(
'locationCapability', 'locationCapability',
[ [
'isOriginal', 'isOriginal',
'persistLocation' 'setPrimaryLocation'
] ]
); );
locationPromise = new ControlledPromise(); locationPromise = new ControlledPromise();
locationCapability.persistLocation.andReturn(locationPromise); locationCapability.setPrimaryLocation
.andReturn(locationPromise);
object = domainObjectFactory({ object = domainObjectFactory({
name: 'object', name: 'object',
@@ -199,7 +200,7 @@ define(
}); });
it("updates location", function () { it("updates location", function () {
expect(locationCapability.persistLocation) expect(locationCapability.setPrimaryLocation)
.toHaveBeenCalled(); .toHaveBeenCalled();
}); });
@@ -223,7 +224,7 @@ define(
}); });
it("does not update location", function () { it("does not update location", function () {
expect(locationCapability.persistLocation) expect(locationCapability.setPrimaryLocation)
.not .not
.toHaveBeenCalled(); .toHaveBeenCalled();
}); });