Permalink
Browse files

Fixed glaring variable scope problem

  • Loading branch information...
Paul
Paul committed Jul 12, 2011
1 parent 544123a commit b21decd1f00454eed50ebc677ba4b5afed368385
Showing with 7 additions and 3 deletions.
  1. +3 −2 index.js
  2. +4 −1 test/resource.path.test.js
View
@@ -264,10 +264,11 @@ Resource.prototype.createRouteHelper = function(mapPath, route) {
// Add to the app.resource object
resourceAccess.path[methodName] = resourceAccess.path[methodName] || function() {
+ var localRoute = route;
Array.prototype.forEach.call(arguments, function(arg) {
- route = route.replace(/:\w+/, arg['id']);
+ localRoute = localRoute.replace(/:\w+/, arg['id']);
});
- return route;
+ return localRoute;
};
}
@@ -15,8 +15,11 @@ module.exports = {
assert.strictEqual(app.resource.path.forums(), '/forums');
assert.strictEqual(app.resource.path.new_forum(), '/forums/new');
assert.strictEqual(app.resource.path.forum({id: 5}), '/forums/5');
+
+ assert.strictEqual(app.resource.path.forum({id: 10}), '/forums/10');
+
assert.strictEqual(app.resource.path.edit_forum({id: 5}), '/forums/5/edit');
- },
+ },
'test shallow nesting': function(){
var app = express.createServer();

0 comments on commit b21decd

Please sign in to comment.