From 65f21865f2c9193b1377cced06932b19580a8526 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Mon, 9 Mar 2015 21:26:45 -0700 Subject: [PATCH 1/3] Correct bug in Registry#findBy, add spec --- lib/registry.js | 4 ++-- spec/lib/registry.spec.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/registry.js b/lib/registry.js index fb56b1c..fa00c4f 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -68,7 +68,7 @@ var Registry = module.exports = { findBy: function(prop, name) { // pluralize, if necessary - if (!/s$/.test(name)) { + if (prop.slice(-1) !== "s") { prop += "s"; } @@ -102,7 +102,7 @@ var Registry = module.exports = { for (var name in this.data) { var repo = this.data[name]; - if (~repo[entry].indexOf(value)) { + if (repo[entry] && ~repo[entry].indexOf(value)) { return repo.module; } } diff --git a/spec/lib/registry.spec.js b/spec/lib/registry.spec.js index 4d77df4..016917d 100644 --- a/spec/lib/registry.spec.js +++ b/spec/lib/registry.spec.js @@ -52,4 +52,22 @@ describe("Registry", function() { }); }); }); + + describe("#findBy", function() { + beforeEach(function() { + stub(Registry, "search"); + }); + + afterEach(function() { + Registry.search.restore(); + }); + + it("calls #search, pluralizing if necessary", function() { + Registry.findBy("adaptors", "testing"); + expect(Registry.search).to.be.calledWith("adaptors", "testing"); + + Registry.findBy("driver", "testing"); + expect(Registry.search).to.be.calledWith("drivers", "testing"); + }); + }); }); From 9030ad45e7c2c0560acbad306abb3071b0d4a497 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Wed, 11 Mar 2015 12:31:45 -0700 Subject: [PATCH 2/3] Add basic #includes helper for arrays --- lib/adaptor.js | 2 +- lib/driver.js | 2 +- lib/registry.js | 5 +++-- lib/utils/helpers.js | 8 ++++++++ spec/lib/utils/helpers.spec.js | 12 ++++++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/adaptor.js b/lib/adaptor.js index 6a2b7ff..bb393f4 100644 --- a/lib/adaptor.js +++ b/lib/adaptor.js @@ -35,7 +35,7 @@ var Adaptor = module.exports = function Adaptor(opts) { this.details = {}; _.each(opts, function(opt, name) { - if (!~["robot", "name", "adaptor", "events"].indexOf(name)) { + if (!_.includes(["robot", "name", "adaptor", "events"], name)) { this.details[name] = opt; } }, this); diff --git a/lib/driver.js b/lib/driver.js index abd8328..a574bfd 100644 --- a/lib/driver.js +++ b/lib/driver.js @@ -39,7 +39,7 @@ var Driver = module.exports = function Driver(opts) { _.each(opts, function(opt, name) { var banned = ["robot", "name", "connection", "driver", "events"]; - if (!~banned.indexOf(name)) { + if (!_.includes(banned, name)) { this.details[name] = opt; } }, this); diff --git a/lib/registry.js b/lib/registry.js index fa00c4f..e64c264 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -12,7 +12,8 @@ "use strict"; -var Logger = require("./logger"); +var Logger = require("./logger"), + _ = require("./utils/helpers"); // Explicitly these modules here, so Browserify can grab them later require("./test/loopback"); @@ -102,7 +103,7 @@ var Registry = module.exports = { for (var name in this.data) { var repo = this.data[name]; - if (repo[entry] && ~repo[entry].indexOf(value)) { + if (repo[entry] && _.includes(repo[entry], value)) { return repo.module; } } diff --git a/lib/utils/helpers.js b/lib/utils/helpers.js index 78fd016..b84c4a1 100644 --- a/lib/utils/helpers.js +++ b/lib/utils/helpers.js @@ -202,3 +202,11 @@ extend(H, { partial: partial, partialRight: partialRight }); + +function includes(arr, value) { + return !!~arr.indexOf(value); +} + +extend(H, { + includes: includes +}); diff --git a/spec/lib/utils/helpers.spec.js b/spec/lib/utils/helpers.spec.js index 4ee7b12..977c499 100644 --- a/spec/lib/utils/helpers.spec.js +++ b/spec/lib/utils/helpers.spec.js @@ -277,4 +277,16 @@ describe("Helpers", function() { expect(fn).to.be.calledWith("one", "two", "three"); }); }); + + describe("#includes", function() { + it("checks if an array includes a value", function() { + var fn = _.includes; + + var arr = [1, "2", 3]; + + expect(fn(arr, 1)).to.be.eql(true); + expect(fn(arr, "2")).to.be.eql(true); + expect(fn(arr, {})).to.be.eql(false); + }); + }); }); From ccc4c070e070a1fe6cd8beef33842f4364fd68e1 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Fri, 3 Apr 2015 11:16:45 -0700 Subject: [PATCH 3/3] Bump version to "0.22.2" --- README.markdown | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 8d2d2a3..85ff861 100644 --- a/README.markdown +++ b/README.markdown @@ -336,6 +336,7 @@ on the [https://github.com/hybridgroup/cylon-site](https://github.com/hybridgrou Version | Notes ------- | ----- +0.22.2 | Bug-fix for Registry loader 0.22.1 | Remove lodash, misc. bug fixes 0.22.0 | API extraction, new devices syntax. 0.21.2 | Update Robeaux version diff --git a/package.json b/package.json index c6e37d3..0228c18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cylon", - "version": "0.22.1", + "version": "0.22.2", "main": "lib/cylon.js", "description": "A JavaScript robotics framework for Node.js", "homepage": "http://cylonjs.com",