Skip to content

Commit

Permalink
Merge pull request #81 from nymag/fix-get
Browse files Browse the repository at this point in the history
fix bad name get
  • Loading branch information
TakenPilot committed Jun 30, 2015
2 parents 0b37a5d + e3bbeb4 commit 14a34d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ function tryRequire(name, paths) {
try {
result = require(path);
} catch (ex) {
if (ex.message && !ex.message.match(/Cannot find module/i)) {
throw ex;
}
result = false;
}
return result;
Expand Down
3 changes: 2 additions & 1 deletion lib/services/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function getName(ref) {
*/
function get(ref, locals) {
var promise,
componentModule = files.getComponentModule(getName(ref));
name = getName(ref),
componentModule = name && files.getComponentModule(name);

if (_.isFunction(componentModule)) {
promise = componentModule(ref, locals);
Expand Down
6 changes: 6 additions & 0 deletions lib/services/components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ describe(_.startCase(filename), function () {
return fn('/components/whatever');
});

it('gets even with bad name', function () {
sandbox.stub(db, 'get').returns(bluebird.resolve('{}'));
sandbox.stub(files, 'getComponentModule').withArgs('whatever').returns(null);
return fn('bad name');
});

it('gets using component module', function () {
sandbox.stub(files, 'getComponentModule').returns(_.constant(bluebird.resolve()));
return fn('/components/whatever');
Expand Down

0 comments on commit 14a34d0

Please sign in to comment.