Merge remote-tracking branch 'upstream/master' into mobile

This commit is contained in:
Shivam Dave
2015-09-01 14:50:45 -07:00
25 changed files with 975 additions and 38 deletions

View File

@@ -50,8 +50,8 @@ define(
function formatTimestamp(timestamp) {
return typeof timestamp === 'number' ?
(moment.utc(timestamp).format(TIME_FORMAT) + " UTC") :
undefined;
(moment.utc(timestamp).format(TIME_FORMAT) + " UTC") :
undefined;
}
function getProperties() {

View File

@@ -72,7 +72,12 @@ define(
*/
PersistenceCapability.prototype.persist = function () {
var domainObject = this.domainObject,
modified = domainObject.getModel().modified;
model = domainObject.getModel(),
modified = model.modified,
persistenceService = this.persistenceService,
persistenceFn = model.persisted !== undefined ?
this.persistenceService.updateObject :
this.persistenceService.createObject;
// Update persistence timestamp...
domainObject.useCapability("mutation", function (model) {
@@ -80,11 +85,11 @@ define(
}, modified);
// ...and persist
return this.persistenceService.updateObject(
return persistenceFn.apply(persistenceService, [
this.getSpace(),
domainObject.getId(),
domainObject.getModel()
);
]);
};
/**

View File

@@ -48,7 +48,7 @@ define(
beforeEach(function () {
mockPersistenceService = jasmine.createSpyObj(
"persistenceService",
[ "updateObject", "readObject" ]
[ "updateObject", "readObject", "createObject", "deleteObject" ]
);
mockDomainObject = {
getId: function () { return id; },
@@ -68,10 +68,24 @@ define(
);
});
it("makes a call to the persistence service when invoked", function () {
it("creates unpersisted objects with the persistence service", function () {
// Verify precondition; no call made during constructor
expect(mockPersistenceService.createObject).not.toHaveBeenCalled();
persistence.persist();
expect(mockPersistenceService.createObject).toHaveBeenCalledWith(
SPACE,
id,
model
);
});
it("updates previously persisted objects with the persistence service", function () {
// Verify precondition; no call made during constructor
expect(mockPersistenceService.updateObject).not.toHaveBeenCalled();
model.persisted = 12321;
persistence.persist();
expect(mockPersistenceService.updateObject).toHaveBeenCalledWith(
@@ -112,4 +126,4 @@ define(
});
}
);
);