Permalink
Browse files

Use object if object[idField] is undefined for path ID. Per discussio…

…n on Issue #20.
  • Loading branch information...
1 parent b1674df commit b4e69aa17c409b1b3df2b3507662f04f527310ec @pacovell pacovell committed Jul 27, 2011
Showing with 12 additions and 1 deletion.
  1. +2 −1 index.js
  2. +10 −0 test/resource.path.test.js
View
@@ -271,7 +271,8 @@ Resource.prototype.createRouteHelper = function(mapPath, route) {
resourceAccess.path[methodName + '_path'] = resourceAccess.path[methodName] || function() {
var localRoute = route;
Array.prototype.forEach.call(arguments, function(arg) {
- localRoute = localRoute.replace(/:\w+/, arg[resourceAccess.path.idField]);
+ var id = arg[resourceAccess.path.idField] || arg;
+ localRoute = localRoute.replace(/:\w+/, id);
});
return localRoute;
};
@@ -108,6 +108,16 @@ module.exports = {
assert.strictEqual(app.resource.path.design_forums_path(), '/forums/design');
assert.strictEqual(app.resource.path.lock_forum_path({id: 5}), '/forums/5/lock');
},
+ 'test resource with direct id value': function(){
+ var app = express.createServer();
+ var ret = app.resource('forums', require('./fixtures/forum'));
+
+ assert.strictEqual(app.resource.path.forum_path(5), '/forums/5');
+ assert.strictEqual(app.resource.path.edit_forum_path(5), '/forums/5/edit');
+
+ assert.strictEqual(app.resource.path.forum_path("5"), '/forums/5');
+ assert.strictEqual(app.resource.path.edit_forum_path("5"), '/forums/5/edit');
+ },
'test resource with custom id field': function(){
var app = express.createServer();
var ret = app.resource('forums', require('./fixtures/forum'));

0 comments on commit b4e69aa

Please sign in to comment.