fix(modeling/cmd): do not fail updating non-changed id

Closes #420
This commit is contained in:
Nico Rehwaldt 2015-11-25 21:53:02 +01:00
parent 9cd5f58ee4
commit 283ddae6d3
2 changed files with 27 additions and 2 deletions

View File

@ -71,7 +71,7 @@ UpdatePropertiesHandler.prototype.execute = function(context) {
properties = context.properties, properties = context.properties,
oldProperties = context.oldProperties || getProperties(businessObject, keys(properties)); oldProperties = context.oldProperties || getProperties(businessObject, keys(properties));
if (ID in properties) { if (isIdChange(properties, businessObject)) {
ids.unclaim(businessObject[ID]); ids.unclaim(businessObject[ID]);
elementRegistry.updateId(element, properties[ID]); elementRegistry.updateId(element, properties[ID]);
@ -126,7 +126,7 @@ UpdatePropertiesHandler.prototype.revert = function(context) {
// update properties // update properties
setProperties(businessObject, oldProperties); setProperties(businessObject, oldProperties);
if (ID in properties) { if (isIdChange(properties, businessObject)) {
ids.unclaim(properties[ID]); ids.unclaim(properties[ID]);
elementRegistry.updateId(element, oldProperties[ID]); elementRegistry.updateId(element, oldProperties[ID]);
@ -134,3 +134,8 @@ UpdatePropertiesHandler.prototype.revert = function(context) {
return context.changed; return context.changed;
}; };
function isIdChange(properties, businessObject) {
return ID in properties && properties[ID] !== businessObject[ID];
}

View File

@ -334,4 +334,24 @@ describe('features/modeling - update properties', function() {
}); });
describe('error handling', function() {
it('should ignore unchanged id', inject(function(elementRegistry, modeling) {
// given
var flowConnection = elementRegistry.get('SequenceFlow_1');
var ids = flowConnection.businessObject.$model.ids;
// when
modeling.updateProperties(flowConnection, { id: 'SequenceFlow_1' });
// then
expect(ids.assigned('SequenceFlow_1')).to.exist;
expect(flowConnection.businessObject.id).to.equal('SequenceFlow_1');
}));
});
}); });