Correct bug in Registry#findBy, add spec

This commit is contained in:
Andrew Stewart 2015-03-09 21:26:45 -07:00
parent e90969eef0
commit 6c5208577a
2 changed files with 20 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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");
});
});
});