Correct bug in Registry#findBy, add spec
This commit is contained in:
parent
e90969eef0
commit
6c5208577a
|
@ -68,7 +68,7 @@ var Registry = module.exports = {
|
||||||
|
|
||||||
findBy: function(prop, name) {
|
findBy: function(prop, name) {
|
||||||
// pluralize, if necessary
|
// pluralize, if necessary
|
||||||
if (!/s$/.test(name)) {
|
if (prop.slice(-1) !== "s") {
|
||||||
prop += "s";
|
prop += "s";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ var Registry = module.exports = {
|
||||||
for (var name in this.data) {
|
for (var name in this.data) {
|
||||||
var repo = this.data[name];
|
var repo = this.data[name];
|
||||||
|
|
||||||
if (~repo[entry].indexOf(value)) {
|
if (repo[entry] && ~repo[entry].indexOf(value)) {
|
||||||
return repo.module;
|
return repo.module;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue