Merge remote-tracking branch 'origin/open1291' into open-1330

This commit is contained in:
larkin 2015-06-25 11:30:33 -07:00
commit abaca86290
3 changed files with 38 additions and 11 deletions

View File

@ -68,6 +68,8 @@ define(
* @returns {DomainObject} the domain object in an editable form * @returns {DomainObject} the domain object in an editable form
*/ */
getEditableObject: function (domainObject) { getEditableObject: function (domainObject) {
var type = domainObject.getCapability('type');
// Track the top-level domain object; this will have // Track the top-level domain object; this will have
// some special behavior for its context capability. // some special behavior for its context capability.
root = root || domainObject; root = root || domainObject;
@ -77,6 +79,11 @@ define(
return domainObject; return domainObject;
} }
// Don't bother wrapping non-editable objects
if (!type || !type.hasFeature('creation')) {
return domainObject;
}
// Provide an editable form of the object // Provide an editable form of the object
return new EditableDomainObject( return new EditableDomainObject(
domainObject, domainObject,
@ -142,4 +149,4 @@ define(
return EditableDomainObjectCache; return EditableDomainObjectCache;
} }
); );

View File

@ -31,7 +31,7 @@ define(
mockQ, mockQ,
mockNavigationService, mockNavigationService,
mockObject, mockObject,
mockCapability, mockType,
controller; controller;
beforeEach(function () { beforeEach(function () {
@ -48,15 +48,18 @@ define(
"domainObject", "domainObject",
[ "getId", "getModel", "getCapability", "hasCapability" ] [ "getId", "getModel", "getCapability", "hasCapability" ]
); );
mockCapability = jasmine.createSpyObj( mockType = jasmine.createSpyObj(
"capability", "type",
[ "invoke" ] [ "hasFeature" ]
); );
mockNavigationService.getNavigation.andReturn(mockObject); mockNavigationService.getNavigation.andReturn(mockObject);
mockObject.getId.andReturn("test"); mockObject.getId.andReturn("test");
mockObject.getModel.andReturn({ name: "Test object" }); mockObject.getModel.andReturn({ name: "Test object" });
mockObject.getCapability.andReturn(mockCapability); mockObject.getCapability.andCallFake(function (key) {
return key === 'type' && mockType;
});
mockType.hasFeature.andReturn(true);
controller = new EditController( controller = new EditController(
mockScope, mockScope,
@ -76,7 +79,7 @@ define(
.toBeDefined(); .toBeDefined();
// Shouldn't have been the mock capability we provided // Shouldn't have been the mock capability we provided
expect(controller.navigatedObject().getCapability("editor")) expect(controller.navigatedObject().getCapability("editor"))
.not.toEqual(mockCapability); .not.toEqual(mockType);
}); });
it("detaches its navigation listener when destroyed", function () { it("detaches its navigation listener when destroyed", function () {
@ -119,4 +122,4 @@ define(
}); });
} }
); );

View File

@ -32,6 +32,7 @@ define(
completionCapability, completionCapability,
object, object,
mockQ, mockQ,
mockType,
cache; cache;
@ -40,10 +41,13 @@ define(
return { return {
getId: function () { return id; }, getId: function () { return id; },
getModel: function () { return {}; }, getModel: function () { return {}; },
getCapability: function (name) { getCapability: function (key) {
return completionCapability; return {
editor: completionCapability,
type: mockType
}[key];
}, },
hasCapability: function (name) { hasCapability: function (key) {
return false; return false;
} }
}; };
@ -62,6 +66,8 @@ define(
beforeEach(function () { beforeEach(function () {
mockQ = jasmine.createSpyObj('$q', ['when', 'all']); mockQ = jasmine.createSpyObj('$q', ['when', 'all']);
mockType = jasmine.createSpyObj('type', ['hasFeature']);
mockType.hasFeature.andReturn(true);
captured = {}; captured = {};
completionCapability = { completionCapability = {
save: function () { save: function () {
@ -152,6 +158,17 @@ define(
.toBe(wrappedObject); .toBe(wrappedObject);
}); });
it("does not wrap non-editable objects", function () {
var domainObject = new TestObject('test-id');
mockType.hasFeature.andCallFake(function (key) {
return key !== 'creation';
});
expect(cache.getEditableObject(domainObject))
.toBe(domainObject);
});
}); });
} }