From 60ed17e32b47ffcd78ccdcf044caf7552f3375ee Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 6 Apr 2015 09:28:53 -0700 Subject: [PATCH 1/3] [Edit] Add test case for double-wrapping Add test case to detect double-wrapping of domain objects retrieved via the editable domain object cache, identified as the root cause of WTD-1071. --- .../objects/EditableDomainObjectCacheSpec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/platform/commonUI/edit/test/objects/EditableDomainObjectCacheSpec.js b/platform/commonUI/edit/test/objects/EditableDomainObjectCacheSpec.js index 001b5a4ad1..1c0d372119 100644 --- a/platform/commonUI/edit/test/objects/EditableDomainObjectCacheSpec.js +++ b/platform/commonUI/edit/test/objects/EditableDomainObjectCacheSpec.js @@ -21,6 +21,9 @@ define( getModel: function () { return {}; }, getCapability: function (name) { return completionCapability; + }, + hasCapability: function (name) { + return false; } }; } @@ -29,6 +32,9 @@ define( var result = Object.create(domainObject); result.wrapped = true; result.wrappedModel = model; + result.hasCapability = function (name) { + return name === 'editor'; + }; captured.wraps = (captured.wraps || 0) + 1; return result; } @@ -112,6 +118,19 @@ define( expect(cache.isRoot(domainObjects[2])).toBeFalsy(); }); + it("does not double-wrap objects", function () { + var domainObject = new TestObject('test-id'), + wrappedObject = cache.getEditableObject(domainObject); + + // Same instance should be returned if you try to wrap + // twice. This is necessary, since it's possible to (e.g.) + // use a context capability on an object retrieved via + // composition, in which case a result will already be + // wrapped. + expect(cache.getEditableObject(wrappedObject)) + .toBe(wrappedObject); + }); + }); } From 8b6a972fa459c1b78cddb725d829b365738b49c2 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 6 Apr 2015 09:30:14 -0700 Subject: [PATCH 2/3] [Edit] Avoid double-wrapping Avoid double-wrapping editable domain objects, WTD-1071. --- .../commonUI/edit/src/objects/EditableDomainObjectCache.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js b/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js index 062d9fa15e..53faaa7ed5 100644 --- a/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js +++ b/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js @@ -51,6 +51,11 @@ define( // some special behavior for its context capability. root = root || domainObject; + // Avoid double-wrapping (WTD-1017) + if (domainObject.hasCapability('editor')) { + return domainObject; + } + // Provide an editable form of the object return new EditableDomainObject( domainObject, From 874f81010c91a267ae57eba76f2201d26f6678ac Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 6 Apr 2015 09:30:42 -0700 Subject: [PATCH 3/3] [Edit] Update EditController spec Update tests for EditController to match updated usage of domain object API for WTD-1071. --- platform/commonUI/edit/test/controllers/EditControllerSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/commonUI/edit/test/controllers/EditControllerSpec.js b/platform/commonUI/edit/test/controllers/EditControllerSpec.js index 6384859de2..09bd4d35cc 100644 --- a/platform/commonUI/edit/test/controllers/EditControllerSpec.js +++ b/platform/commonUI/edit/test/controllers/EditControllerSpec.js @@ -25,7 +25,7 @@ define( ); mockObject = jasmine.createSpyObj( "domainObject", - [ "getId", "getModel", "getCapability" ] + [ "getId", "getModel", "getCapability", "hasCapability" ] ); mockCapability = jasmine.createSpyObj( "capability",