Extract Entity#created and Entity#modified

This commit is contained in:
John Firebaugh
2012-11-26 21:48:40 -04:00
parent 447b89fa01
commit cc7328d1c9
5 changed files with 57 additions and 12 deletions
+2 -2
View File
@@ -64,7 +64,7 @@ iD.modes.AddRoad = {
tags: {
highway: 'residential'
},
modified: true,
_updated: true,
id: iD.Util.id('way')
});
},
@@ -184,7 +184,7 @@ iD.modes.AddArea = {
tags: {
building: 'yes'
},
modified: true,
_updated: true,
id: iD.Util.id('way')
});
},
+9 -1
View File
@@ -4,7 +4,7 @@ iD.Entity = function(a, b) {
_.extend(this, {tags: {}}, a, b);
if (b) {
this.modified = true;
this._updated = true;
}
if (iD.debug) {
@@ -16,5 +16,13 @@ iD.Entity = function(a, b) {
iD.Entity.prototype = {
update: function(attrs) {
return iD.Entity(this, attrs);
},
created: function() {
return this._updated && +this.id.slice(1) < 0;
},
modified: function() {
return this._updated && +this.id.slice(1) > 0;
}
};
+2 -7
View File
@@ -91,15 +91,10 @@ iD.Graph.prototype = {
},
modifications: function() {
return _.filter(this.entities, function(entity) {
return ((+entity.id.slice(1) > 0)) && entity.modified;
});
return _.filter(this.entities, function(entity) { return entity.modified(); });
},
creations: function() {
return _.filter(this.entities, function(entity) {
return ((+entity.id.slice(1)) < 0) && entity.modified;
});
return _.filter(this.entities, function(entity) { return entity.created(); });
}
};
+26 -2
View File
@@ -12,9 +12,33 @@ describe('Entity', function () {
e = iD.Entity().update({tags: tags});
expect(e.tags).toBe(tags);
});
});
it("returns a modified Entity", function () {
expect(iD.Entity().update({}).modified).toBeTruthy();
describe("#created", function () {
it("returns false for an unmodified Entity", function () {
expect(iD.Entity().created()).toBeFalsy();
});
it("returns false for a modified Entity with positive ID", function () {
expect(iD.Entity({id: 'w1234'}).update({}).created()).toBeFalsy();
});
it("returns true for a modified Entity with negative ID", function () {
expect(iD.Entity({id: 'w-1234'}).update({}).created()).toBeTruthy();
});
});
describe("#modified", function () {
it("returns false for an unmodified Entity", function () {
expect(iD.Entity().modified()).toBeFalsy();
});
it("returns true for a modified Entity with positive ID", function () {
expect(iD.Entity({id: 'w1234'}).update({}).modified()).toBeTruthy();
});
it("returns false for a modified Entity with negative ID", function () {
expect(iD.Entity({id: 'w-1234'}).update({}).modified()).toBeFalsy();
});
});
});
+18
View File
@@ -53,4 +53,22 @@ describe('Graph', function() {
expect(g2.entity('n-1').lat).toEqual(40);
});
});
describe("#modifications", function () {
it("filters entities by modified", function () {
var a = {modified: function () { return true; }},
b = {modified: function () { return false; }},
graph = iD.Graph([a, b]);
expect(graph.modifications()).toEqual([a]);
});
});
describe("#creations", function () {
it("filters entities by created", function () {
var a = {created: function () { return true; }},
b = {created: function () { return false; }},
graph = iD.Graph([a, b]);
expect(graph.creations()).toEqual([a]);
});
})
});