Permalink
Browse files

Merge pull request #73 from vesln/path-array

  • Loading branch information...
2 parents d284369 + 8e771eb commit 0e62b87169bbde297af55dbde109724f913ab8db @pksunkara pksunkara committed Mar 22, 2012
Showing with 45 additions and 2 deletions.
  1. +7 −1 lib/director/router.js
  2. +0 −1 test/server/cli/mount-test.js
  3. +38 −0 test/server/core/on-test.js
View
@@ -179,7 +179,7 @@ Router.prototype.param = function (token, matcher) {
//
// ### function on (method, path, route)
// #### @method {string} **Optional** Method to use
-// #### @path {string} Path to set this route on.
+// #### @path {Array|string} Path to set this route on.
// #### @route {Array|function} Handler for the specified method and path.
// Adds a new `route` to this instance for the specified `method`
// and `path`.
@@ -196,6 +196,12 @@ Router.prototype.on = Router.prototype.route = function (method, path, route) {
path = method;
method = 'on';
}
+
+ if (Array.isArray(path)) {
+ return path.forEach(function(p) {
+ self.on(method, p, route);
+ });
+ }
if (path.source) {
path = path.source.replace(/\\\//ig, '/');
@@ -21,7 +21,6 @@ vows.describe('director/cli/path').addBatch({
}
}),
"should create the correct nested routing table": function (router) {
- console.log(router.routes);
assert.isObject(router.routes.apps);
assert.isFunction(router.routes.apps.on);
assert.isObject(router.routes.users);
@@ -0,0 +1,38 @@
+/*
+ * on-test.js: Tests for the on/route method.
+ *
+ * (C) 2011, Nodejitsu Inc.
+ * MIT LICENSE
+ *
+ */
+
+var assert = require('assert'),
+ vows = require('vows'),
+ director = require('../../../lib/director');
+
+vows.describe('director/router/insert').addBatch({
+ "An instance of director.Router": {
+ topic: new director.Router(),
+ "the on() method": {
+ "['foo', 'bar']": function (router) {
+ function noop () { }
+
+ router.on(['foo', 'bar'], noop);
+ assert.strictEqual(router.routes.foo.on, noop);
+ assert.strictEqual(router.routes.bar.on, noop);
+ },
+ "'baz'": function (router) {
+ function noop () { }
+
+ router.on('baz', noop);
+ assert.strictEqual(router.routes.baz.on, noop);
+ },
+ "'after', 'baz'": function (router) {
+ function noop () { }
+
+ router.on('after', 'boo', noop);
+ assert.strictEqual(router.routes.boo.after, noop);
+ }
+ }
+ }
+}).export(module);

0 comments on commit 0e62b87

Please sign in to comment.