[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
* 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

View File

@ -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 () {

View File

@ -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);

View File

@ -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();
});