Browse files

Added public `app.routes`. Closes #887

keep things simple for now :)
  • Loading branch information...
1 parent 0fca62c commit 18cdb3d845313c7da77e2b3c3f86081129804f7a @tj tj committed May 2, 2012
Showing with 49 additions and 1 deletion.
  1. +1 −1 lib/application.js
  2. +48 −0 test/app.routes.js
View
2 lib/application.js
@@ -93,7 +93,7 @@ app.defaultConfiguration = function(){
// router
this._router = new Router(this);
- this.routes = this._router.routes;
+ this.routes = this._router.map;
this.__defineGetter__('router', function(){
this._usedRouter = true;
this._router.caseSensitive = this.enabled('case sensitive routing');
View
48 test/app.routes.js
@@ -0,0 +1,48 @@
+
+var express = require('../')
+ , assert = require('assert')
+ , request = require('./support/http');
+
+describe('app.routes', function(){
+ it('should be initialized', function(){
+ var app = express();
+ app.routes.should.eql({});
+ })
+
+ it('should be populated with routes', function(){
+ var app = express();
+
+ app.get('/', function(req, res){});
+ app.get('/user/:id', function(req, res){});
+
+ var get = app.routes.get;
+ get.should.have.length(2);
+
+ get[0].path.should.equal('/');
+ get[0].method.should.equal('get');
+ get[0].regexp.toString().should.equal('/^\\/\\/?$/i');
+
+ get[1].path.should.equal('/user/:id');
+ get[1].method.should.equal('get');
+ })
+
+ it('should be mutable', function(done){
+ var app = express();
+
+ app.get('/', function(req, res){});
+ app.get('/user/:id', function(req, res){});
+
+ var get = app.routes.get;
+ get.should.have.length(2);
+
+ get[0].path.should.equal('/');
+ get[0].method.should.equal('get');
+ get[0].regexp.toString().should.equal('/^\\/\\/?$/i');
+
+ get.splice(1);
+
+ request(app)
+ .get('/user/12')
+ .expect(404, done);
+ })
+})

0 comments on commit 18cdb3d

Please sign in to comment.