Merge pull request #780 from nasa/open715

[Timelines] #715 Added a check to prevent mutation when modes are unchanged
This commit is contained in:
Victor Woeltjen 2016-03-22 09:24:57 -07:00
commit f8682a7a29
2 changed files with 25 additions and 5 deletions

View File

@ -45,11 +45,13 @@ define(
function modes(value) {
// Can be used as a setter...
if (arguments.length > 0 && Array.isArray(value)) {
// Update the relationships
mutator.mutate(function (model) {
model.relationships = model.relationships || {};
model.relationships[ACTIVITY_RELATIONSHIP] = value;
}).then(persister.persist);
if ((model.relationships || {})[ACTIVITY_RELATIONSHIP] !== value) {
// Update the relationships
mutator.mutate(function (model) {
model.relationships = model.relationships || {};
model.relationships[ACTIVITY_RELATIONSHIP] = value;
}).then(persister.persist);
}
}
// ...otherwise, use as a getter
return (model.relationships || {})[ACTIVITY_RELATIONSHIP] || [];

View File

@ -32,12 +32,14 @@ define(
mockCapabilities,
testModel,
mockPromise,
testModes,
decorator;
beforeEach(function () {
mockSwimlane = {};
mockCapabilities = {};
testModel = {};
testModes = ['a', 'b', 'c'];
mockSelection = jasmine.createSpyObj('selection', ['select', 'get']);
@ -135,6 +137,22 @@ define(
expect(mockCapabilities.persistence.persist).toHaveBeenCalled();
});
it("does not mutate modes when unchanged", function () {
testModel.relationships = { modes: testModes };
decorator.modes(testModes);
expect(mockCapabilities.mutation.mutate).not.toHaveBeenCalled();
expect(testModel.relationships.modes).toEqual(testModes);
});
it("does mutate modes when changed", function () {
var testModes2 = ['d', 'e', 'f'];
testModel.relationships = { modes: testModes };
decorator.modes(testModes2);
expect(mockCapabilities.mutation.mutate).toHaveBeenCalled();
mockCapabilities.mutation.mutate.mostRecentCall.args[0](testModel);
expect(testModel.relationships.modes).toBe(testModes2);
});
it("does not provide a 'remove' method with no parent", function () {
expect(decorator.remove).not.toEqual(jasmine.any(Function));
});