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()); }); }); });