Merge branch 'open1098' into open-master

This commit is contained in:
Victor Woeltjen 2015-04-24 09:09:42 -07:00
commit a2bdeda1a0
4 changed files with 62 additions and 0 deletions

View File

@ -7,6 +7,11 @@
"depends": [ "$injector" ], "depends": [ "$injector" ],
"message": "Objects of this type cannot contain objects of that type." "message": "Objects of this type cannot contain objects of that type."
}, },
{
"category": "composition",
"implementation": "CompositionMutabilityPolicy.js",
"message": "Objects of this type cannot be modified."
},
{ {
"category": "action", "category": "action",
"implementation": "ComposeActionPolicy.js", "implementation": "ComposeActionPolicy.js",

View File

@ -0,0 +1,30 @@
/*global define*/
define(
[],
function () {
"use strict";
/**
* Disallow composition changes to objects which are not mutable.
* @constructor
*/
function CompositionMutabilityPolicy() {
return {
/**
* Is the type identified by the candidate allowed to
* contain the type described by the context?
* @param {Type} candidate the type of domain object
*/
allow: function (candidate) {
// Equate creatability with mutability; that is, users
// can only modify objects of types they can create, and
// vice versa.
return candidate.hasFeature('creation');
}
};
}
return CompositionMutabilityPolicy;
}
);

View File

@ -0,0 +1,26 @@
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
define(
["../src/CompositionMutabilityPolicy"],
function (CompositionMutabilityPolicy) {
"use strict";
describe("The composition mutability policy", function () {
var mockType,
policy;
beforeEach(function () {
mockType = jasmine.createSpyObj('type', ['hasFeature']);
policy = new CompositionMutabilityPolicy();
});
it("only allows composition for types which will have a composition capability", function () {
expect(policy.allow(mockType)).toBeFalsy();
mockType.hasFeature.andReturn(true);
expect(policy.allow(mockType)).toBeTruthy();
expect(mockType.hasFeature).toHaveBeenCalledWith('creation');
});
});
}
);

View File

@ -1,6 +1,7 @@
[ [
"CapabilityTable", "CapabilityTable",
"ComposeActionPolicy", "ComposeActionPolicy",
"CompositionMutabilityPolicy",
"CompositionPolicy", "CompositionPolicy",
"ContainmentTable" "ContainmentTable"
] ]