Simplify coercion of Robot to JSON
This commit is contained in:
parent
d0c29822ff
commit
026d3777e6
25
lib/robot.js
25
lib/robot.js
|
@ -128,25 +128,16 @@ Robot.randomName = function() {
|
|||
//
|
||||
// Returns an Object containing Robot data
|
||||
Robot.prototype.toJSON = function() {
|
||||
var connections = (function() {
|
||||
var results = [];
|
||||
var devices = [],
|
||||
connections = [];
|
||||
|
||||
for (var n in this.connections) {
|
||||
results.push(this.connections[n].toJSON());
|
||||
}
|
||||
for (var n in this.connections) {
|
||||
connections.push(this.connections[n]);
|
||||
}
|
||||
|
||||
return results;
|
||||
}).call(this);
|
||||
|
||||
var devices = (function() {
|
||||
var results = [];
|
||||
|
||||
for (var n in this.devices) {
|
||||
results.push(this.devices[n].toJSON());
|
||||
}
|
||||
|
||||
return results;
|
||||
}).call(this);
|
||||
for (var n in this.devices) {
|
||||
devices.push(this.devices[n]);
|
||||
}
|
||||
|
||||
return {
|
||||
name: this.name,
|
||||
|
|
|
@ -119,13 +119,11 @@ describe("Robot", function() {
|
|||
});
|
||||
|
||||
it("contains the robot's devices", function() {
|
||||
var deviceJSON = bot.devices.ping.toJSON();
|
||||
expect(json.devices).to.eql([deviceJSON]);
|
||||
expect(json.devices).to.eql([bot.devices.ping]);
|
||||
});
|
||||
|
||||
it("contains the robot's connections", function() {
|
||||
var connectionJSON = bot.connections.loopback.toJSON();
|
||||
expect(json.connections).to.eql([connectionJSON]);
|
||||
expect(json.connections).to.eql([bot.connections.loopback]);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue