Merge pull request #1016 from nasa/fix-1013

[Persistence] Use identifier service to get key
This commit is contained in:
Victor Woeltjen 2016-06-15 11:18:13 -07:00 committed by GitHub
commit 6878c59f45
2 changed files with 18 additions and 10 deletions

View File

@ -60,11 +60,6 @@ define(
this.$q = $q;
}
function getKey(id) {
var parts = id.split(":");
return parts.length > 1 ? parts.slice(1).join(":") : id;
}
/**
* Checks if the value returned is falsey, and if so returns a
* rejected promise
@ -131,7 +126,7 @@ define(
// ...and persist
return persistenceFn.apply(persistenceService, [
this.getSpace(),
getKey(domainObject.getId()),
this.getKey(),
domainObject.getModel()
]).then(function (result) {
return rejectIfFalsey(result, self.$q);
@ -159,7 +154,7 @@ define(
return this.persistenceService.readObject(
this.getSpace(),
this.domainObject.getId()
this.getKey()
).then(updateModel);
};
@ -178,6 +173,17 @@ define(
return this.identifierService.parse(id).getSpace();
};
/**
* Get the key for this domain object in the given space.
*
* @returns {string} the key of the object in it's space.
*/
PersistenceCapability.prototype.getKey = function () {
var id = this.domainObject.getId();
return this.identifierService.parse(id).getKey();
};
return PersistenceCapability;
}
);

View File

@ -35,7 +35,8 @@ define(
mockNofificationService,
mockCacheService,
mockQ,
id = "object id",
key = "persistence key",
id = "object identifier",
model,
SPACE = "some space",
persistence,
@ -101,6 +102,7 @@ define(
});
mockIdentifierService.parse.andReturn(mockIdentifier);
mockIdentifier.getSpace.andReturn(SPACE);
mockIdentifier.getKey.andReturn(key);
persistence = new PersistenceCapability(
mockCacheService,
mockPersistenceService,
@ -124,7 +126,7 @@ define(
expect(mockPersistenceService.createObject).toHaveBeenCalledWith(
SPACE,
id,
key,
model
);
});
@ -138,7 +140,7 @@ define(
expect(mockPersistenceService.updateObject).toHaveBeenCalledWith(
SPACE,
id,
key,
model
);
});