Merge pull request #1445 from nasa/api-updates

Api updates
This commit is contained in:
Andrew Henry
2017-02-21 17:04:45 -08:00
committed by GitHub
10 changed files with 127 additions and 166 deletions

View File

@@ -48,9 +48,10 @@ define(
* Decorate PersistenceCapability to queue persistence calls when a
* transaction is in progress.
*/
TransactionCapabilityDecorator.prototype.getCapabilities = function (model) {
TransactionCapabilityDecorator.prototype.getCapabilities = function () {
var self = this,
capabilities = this.capabilityService.getCapabilities(model),
capabilities = this.capabilityService.getCapabilities
.apply(this.capabilityService, arguments),
persistenceCapability = capabilities.persistence;
capabilities.persistence = function (domainObject) {

View File

@@ -53,10 +53,10 @@ define(
*/
function CoreCapabilityProvider(capabilities, $log) {
// Filter by invoking the capability's appliesTo method
function filterCapabilities(model) {
function filterCapabilities(model, id) {
return capabilities.filter(function (capability) {
return capability.appliesTo ?
capability.appliesTo(model) :
capability.appliesTo(model, id) :
true;
});
}
@@ -75,8 +75,8 @@ define(
return result;
}
function getCapabilities(model) {
return packageCapabilities(filterCapabilities(model));
function getCapabilities(model, id) {
return packageCapabilities(filterCapabilities(model, id));
}
return {

View File

@@ -50,7 +50,7 @@ define(
this.capabilityService = capabilityService;
}
QueuingPersistenceCapabilityDecorator.prototype.getCapabilities = function (model) {
QueuingPersistenceCapabilityDecorator.prototype.getCapabilities = function (model, id) {
var capabilityService = this.capabilityService,
persistenceQueue = this.persistenceQueue;
@@ -76,7 +76,7 @@ define(
}
return decoratePersistence(
capabilityService.getCapabilities(model)
capabilityService.getCapabilities(model, id)
);
};

View File

@@ -32,6 +32,7 @@ define(
mockPersistence,
mockDomainObject,
testModel,
testId,
decorator;
beforeEach(function () {
@@ -41,6 +42,7 @@ define(
['getCapabilities']
);
testModel = { someKey: "some value" };
testId = 'someId';
mockPersistence = jasmine.createSpyObj(
'persistence',
['persist', 'refresh']
@@ -67,9 +69,9 @@ define(
// QueuingPersistenceCapability itself, which has its own tests.
it("delegates to its wrapped service", function () {
decorator.getCapabilities(testModel);
decorator.getCapabilities(testModel, testId);
expect(mockCapabilityService.getCapabilities)
.toHaveBeenCalledWith(testModel);
.toHaveBeenCalledWith(testModel, testId);
});
it("wraps its persistence capability's constructor", function () {