diff --git a/lib/router.js b/lib/router.js index bf8376331..b0d5afd53 100644 --- a/lib/router.js +++ b/lib/router.js @@ -196,7 +196,7 @@ Router.prototype.mount = function mount(opts, handlers) { * @instance * @function unmount * @param {String} name - the route name - * @returns {String} the name of the deleted route. + * @returns {Object|undefined} removed route if found */ Router.prototype.unmount = function unmount(name) { assert.string(name, 'name'); @@ -204,14 +204,12 @@ Router.prototype.unmount = function unmount(name) { var route = this._mounts[name]; if (!route) { - return; + return undefined; } - // TODO: revisit - throw new Error('Unmount is not implemented'); - // this._findMyWay.off(route.method, route.path); - // delete this._mounts[name]; - // return route; + this._findMyWay.off(route.method, route.path); + delete this._mounts[name]; + return route; }; /** diff --git a/package.json b/package.json index 4ada782dd..046c6ffb4 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "escape-regexp-component": "^1.0.2", "ewma": "^2.0.1", "finalhandler": "1.1.0", - "find-my-way": "1.7.1", + "find-my-way": "1.8.0", "formidable": "^1.1.1", "http-signature": "^1.2.0", "lodash": "^4.17.4", diff --git a/test/server.test.js b/test/server.test.js index 33e05ae48..6e1fae76a 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -177,30 +177,30 @@ test('use + get (path only)', function(t) { }); }); -// test('rm', function(t) { -// var route = SERVER.get('/foo/:id', function foosy(req, res, next) { -// next(); -// }); -// -// SERVER.get('/bar/:id', function barsy(req, res, next) { -// t.ok(req.params); -// t.equal(req.params.id, 'foo'); -// res.send(); -// next(); -// }); -// -// t.ok(SERVER.rm(route)); -// -// CLIENT.get('/foo/bar', function(err, _, res) { -// t.ok(err); -// t.equal(res.statusCode, 404); -// CLIENT.get('/bar/foo', function(err2, __, res2) { -// t.ifError(err2); -// t.equal(res2.statusCode, 200); -// t.end(); -// }); -// }); -// }); +test('rm', function(t) { + var routeName = SERVER.get('/foo/:id', function foosy(req, res, next) { + next(); + }); + + SERVER.get('/bar/:id', function barsy(req, res, next) { + t.ok(req.params); + t.equal(req.params.id, 'foo'); + res.send(); + next(); + }); + + t.ok(SERVER.rm(routeName)); + + CLIENT.get('/foo/bar', function(err, _, res) { + t.ok(err); + t.equal(res.statusCode, 404); + CLIENT.get('/bar/foo', function(err2, __, res2) { + t.ifError(err2); + t.equal(res2.statusCode, 200); + t.end(); + }); + }); +}); test('use - throws TypeError on non function as argument', function(t) { var errMsg = 'handler (function) is required';