diff --git a/src/router.js b/src/router.js index fe60225..1e7ff52 100644 --- a/src/router.js +++ b/src/router.js @@ -132,7 +132,7 @@ module.exports = function(source) { // GET /:resource/:id function show(req, res, next) { var resource = db(req.params.resource) - .get(+req.params.id) + .get(utils.toNative(req.params.id)) if (resource) { res.jsonp(resource) @@ -161,7 +161,7 @@ module.exports = function(source) { } var resource = db(req.params.resource) - .update(+req.params.id, req.body) + .update(utils.toNative(req.params.id), req.body) if (resource) { res.jsonp(resource) @@ -172,7 +172,7 @@ module.exports = function(source) { // DELETE /:resource/:id function destroy(req, res, next) { - db(req.params.resource).remove(+req.params.id) + db(req.params.resource).remove(utils.toNative(req.params.id)) // Remove dependents documents var removable = utils.getRemovable(db.object) diff --git a/test/index.js b/test/index.js index aa8c487..1aad739 100644 --- a/test/index.js +++ b/test/index.js @@ -167,6 +167,14 @@ describe('Server', function() { .expect(200, done) }) + it('should support string id, respond with json and corresponding resource', function(done) { + request(server) + .get('/refs/abcd-1234') + .expect('Content-Type', /json/) + .expect(db.refs[0]) + .expect(200, done) + }) + it('should respond with 404 if resource is not found', function(done) { request(server) .get('/posts/9001')