Refactored some CopyService functions out to CopyTask

This commit is contained in:
Henry 2015-11-05 16:39:46 -08:00
parent aa2a835cb1
commit e1c6c76612
3 changed files with 13 additions and 19 deletions

View File

@ -23,8 +23,11 @@
/*global define */
define(
["uuid"],
function (uuid) {
[
"uuid",
"./CopyTask"
],
function (uuid, CopyTask) {
"use strict";
/**

View File

@ -50,7 +50,7 @@ define(
clone.model.persisted = self.now();
return self.persistenceService.createObject(clone.persistenceSpace, clone.id, clone.model)
.then(function(){
return self.deferred.notify({phase: "copying", totalObjects: objectClones.length, processed: ++persisted});
return self.deferred.notify({phase: "copying", totalObjects: objectClones.length, processed: ++self.persisted});
});
})).then(function(){
return objectClones;
@ -66,7 +66,7 @@ define(
self = this;
if (!this.parent.hasCapability('composition')){
return this.deferred.reject();
return this.$q.reject();
}
return this.persistenceService
@ -145,7 +145,7 @@ define(
}
return copy(self.domainObject, self.parent).then(function(domainObjectClone){
domainObjectClone.model.location = parent.getId();
domainObjectClone.model.location = self.parent.getId();
return clones;
});
};
@ -156,11 +156,12 @@ define(
this.deferred = this.$q.defer();
return this.buildCopyPlan()
this.buildCopyPlan()
.then(persistObjects)
.then(addClonesToParent)
.then(this.deferred.resolve)
.catch(this.deferred.reject);
.then(this.deferred.resolve, this.deferred.reject);
return this.deferred.promise;
}
return CopyTask;

View File

@ -342,17 +342,7 @@ define(
expect(copyFinished.mostRecentCall.args[0].model.modified).toBeUndefined();
expect(copyFinished.mostRecentCall.args[0].model.persisted).toBe(mockNow.now());
});
/**
Preserves links
*/
it ("preserves links", function() {
expect(copyFinished.mostRecentCall.args[0].model.location).toBe("testLocation");
});
/**
Preserves links
*/
it ("correctly locates cloned objects", function() {
expect(mockPersistenceService.createObject.calls[0].args[2].location).toEqual(mockPersistenceService.createObject.calls[1].args[1]);
});