[Instantiation] Ensure new models have modified timestamp

...to avoid https://github.com/nasa/openmct/issues/745#issuecomment-204561163
This commit is contained in:
Victor Woeltjen 2016-04-01 14:27:26 -07:00
parent da09ffd3fa
commit 70acef6905
3 changed files with 20 additions and 3 deletions

View File

@ -355,7 +355,8 @@ define([
"implementation": InstantiationCapability, "implementation": InstantiationCapability,
"depends": [ "depends": [
"$injector", "$injector",
"identifierService" "identifierService",
"now"
] ]
} }
], ],

View File

@ -35,10 +35,16 @@ define(
* @param $injector Angular's `$injector` * @param $injector Angular's `$injector`
* @implements {Capability} * @implements {Capability}
*/ */
function InstantiationCapability($injector, identifierService, domainObject) { function InstantiationCapability(
$injector,
identifierService,
now,
domainObject
) {
this.$injector = $injector; this.$injector = $injector;
this.identifierService = identifierService; this.identifierService = identifierService;
this.domainObject = domainObject; this.domainObject = domainObject;
this.now = now;
} }
/** /**
@ -57,6 +63,8 @@ define(
space = parsedId.getDefinedSpace(), space = parsedId.getDefinedSpace(),
id = this.identifierService.generate(space); id = this.identifierService.generate(space);
model.modified = this.now();
// Lazily initialize; instantiate depends on capabilityService, // Lazily initialize; instantiate depends on capabilityService,
// which depends on all capabilities, including this one. // which depends on all capabilities, including this one.
this.instantiateFn = this.instantiateFn || this.instantiateFn = this.instantiateFn ||

View File

@ -31,6 +31,7 @@ define(
mockIdentifierService, mockIdentifierService,
mockInstantiate, mockInstantiate,
mockIdentifier, mockIdentifier,
mockNow,
mockDomainObject, mockDomainObject,
instantiation; instantiation;
@ -57,9 +58,13 @@ define(
mockIdentifierService.parse.andReturn(mockIdentifier); mockIdentifierService.parse.andReturn(mockIdentifier);
mockIdentifierService.generate.andReturn("some-id"); mockIdentifierService.generate.andReturn("some-id");
mockNow = jasmine.createSpy();
mockNow.andReturn(1234321);
instantiation = new InstantiationCapability( instantiation = new InstantiationCapability(
mockInjector, mockInjector,
mockIdentifierService, mockIdentifierService,
mockNow,
mockDomainObject mockDomainObject
); );
}); });
@ -81,7 +86,10 @@ define(
expect(instantiation.instantiate(testModel)) expect(instantiation.instantiate(testModel))
.toBe(mockDomainObject); .toBe(mockDomainObject);
expect(mockInstantiate) expect(mockInstantiate)
.toHaveBeenCalledWith(testModel, jasmine.any(String)); .toHaveBeenCalledWith({
someKey: "some value",
modified: mockNow()
}, jasmine.any(String));
}); });
}); });