diff --git a/js/id/graph/graph.js b/js/id/graph/graph.js index d9118045a..eae11cc15 100644 --- a/js/id/graph/graph.js +++ b/js/id/graph/graph.js @@ -189,6 +189,9 @@ iD.Graph.prototype = { }, replace: function(entity) { + if (this.entities[entity.id] === entity) + return this; + return this.update(function () { this._updateCalculated(this.entities[entity.id], entity); this.entities[entity.id] = entity; diff --git a/test/spec/graph/graph.js b/test/spec/graph/graph.js index a357ff360..a099d8b61 100644 --- a/test/spec/graph/graph.js +++ b/test/spec/graph/graph.js @@ -196,10 +196,16 @@ describe('iD.Graph', function() { }); describe("#replace", function () { + it("is a no-op if the replacement is identical to the existing entity", function () { + var node = iD.Node(), + graph = iD.Graph([node]); + expect(graph.replace(node)).to.equal(graph); + }); + it("returns a new graph", function () { var node = iD.Node(), graph = iD.Graph([node]); - expect(graph.replace(node)).not.to.equal(graph); + expect(graph.replace(node.update())).not.to.equal(graph); }); it("doesn't modify the receiver", function () { @@ -257,7 +263,6 @@ describe('iD.Graph', function() { graph = iD.Graph([node, r1]); expect(graph.replace(r1).parentRelations(node)).to.eql([r1]); }); - }); describe("#update", function () {