Skip to content

Commit

Permalink
Use object if object[idField] is undefined for path ID. Per discussio…
Browse files Browse the repository at this point in the history
…n on Issue visionmedia#20.
  • Loading branch information
Paul Covell committed Jul 27, 2011
1 parent b1674df commit b4e69aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
10 changes: 10 additions & 0 deletions test/resource.path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit b4e69aa

Please sign in to comment.