From baec0f971909092edcfe1e952cd1d3582de2262c Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 3 Dec 2015 15:28:07 -0800 Subject: [PATCH] #338 added new test case for creation of links when object type is not createable --- platform/entanglement/src/services/CopyTask.js | 14 ++++++++------ .../entanglement/test/services/CopyServiceSpec.js | 12 ++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/platform/entanglement/src/services/CopyTask.js b/platform/entanglement/src/services/CopyTask.js index d3790bf433..a12bdf2f11 100644 --- a/platform/entanglement/src/services/CopyTask.js +++ b/platform/entanglement/src/services/CopyTask.js @@ -39,6 +39,7 @@ define( function CopyTask (domainObject, parent, policyService, $q){ this.domainObject = domainObject; this.parent = parent; + this.firstClone = undefined; this.$q = $q; this.deferred = undefined; this.policyService = policyService; @@ -97,12 +98,10 @@ define( * Will add a list of clones to the specified parent's composition */ function addClonesToParent(self) { - var parentClone = self.clones[self.clones.length-1]; - - return parentClone.getCapability("persistence").persist() - .then(function(){self.parent.getCapability("composition").add(parentClone.getId())}) + return self.firstClone.getCapability("persistence").persist() + .then(function(){self.parent.getCapability("composition").add(self.firstClone.getId())}) .then(function(){return self.parent.getCapability("persistence").persist();}) - .then(function(){return parentClone;}); + .then(function(){return self.firstClone;}); } /** @@ -188,7 +187,10 @@ define( var self = this; return this.copy(self.domainObject, self.parent).then(function(domainObjectClone){ - domainObjectClone.getModel().location = self.parent.getId(); + if (domainObjectClone !== self.domainObject) { + domainObjectClone.getModel().location = self.parent.getId(); + } + self.firstClone = domainObjectClone; return self; }); }; diff --git a/platform/entanglement/test/services/CopyServiceSpec.js b/platform/entanglement/test/services/CopyServiceSpec.js index a6815a314a..d4de5aa2aa 100644 --- a/platform/entanglement/test/services/CopyServiceSpec.js +++ b/platform/entanglement/test/services/CopyServiceSpec.js @@ -390,16 +390,20 @@ define( }); describe("when cloning non-creatable objects", function() { beforeEach(function () { - policyService.allow.callFake(function(category, object){ - return category === 'creation'; + policyService.allow.andCallFake(function(category){ + //Return false for 'creation' policy + return category !== 'creation'; }); copyResult = copyService.perform(object, newParent); copyFinished = jasmine.createSpy('copyFinished'); copyResult.then(copyFinished); }); - it ("creates links", function() { - expect(childObjectClone.getModel().location).toEqual(objectClone.getId()); + it ("creates link instead of clone", function() { + var copiedObject = copyFinished.calls[0].args[0]; + expect(copiedObject).toBe(object); + expect(compositionCapability.add).toHaveBeenCalledWith(copiedObject.getId()); + //expect(newParent.getModel().composition).toContain(copiedObject.getId()); }); }); });