add app.VERB() paths array deprecation warning
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 0d40c65 · Browse files · 2 files·+30 added−43 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+30 added−43 removed
- tests:+25 added−43 removed
- other:+5 added−0 removed
Provenance
- Commit
91c71d6- Tree
ed6d5e0- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
0d40c65
2 files changed+30 added−43 removed
modified:lib/application.js+5 added
400 unmodified lines401 methods.forEach(function(method){402 app[method] = function(path){403 if ('get' == method && 1 == arguments.length) return this.set(path);404 405+ // deprecated406+ if (Array.isArray(path)) {407+ console.trace('passing an array to app.VERB() is deprecated and will be removed in 4.0');408+ }409+410 // if no router attached yet, attach the router411 if (!this._usedRouter) this.use(this.router);412 413 // setup route123 unmodified linesmodified:test/app.router.js+25 added-43 removed
46 unmodified lines47 app.use(function(req, res, next){48 calls.push('before');49 next();50 });51- 51+52 app.use(app.router);53 54 app.use(function(req, res, next){55 calls.push('after');11 unmodified lines67 calls.should.eql(['before', 'GET /', 'after'])68 done();69 })70 })71- 71+72 it('should be auto .use()d on the first app.VERB() call', function(done){73 var app = express();74 75 var calls = [];1 unmodified line77 app.use(function(req, res, next){78 calls.push('before');79 next();80 });81- 81+82 app.get('/', function(req, res, next){83 calls.push('GET /')84 next();85 });22 unmodified lines108 request(app)109 .get('/user/12?foo=bar')110 .expect('user', done);111 })112- 112+113 it('should populate req.params with the captures', function(done){114 var app = express();115 116 app.get(/^\/user\/([0-9]+)\/(view|edit)?$/, function(req, res){6 unmodified lines123 .get('/user/10/edit')124 .expect('editing user 10', done);125 })126 })127- 128- describe('when given an array', function(){129- it('should match all paths in the array', function(done){130- var app = express();131- 132- app.get(['/one', '/two'], function(req, res){133- res.end('works');134- });135- 136- request(app)137- .get('/one')138- .expect('works', function() {139- request(app)140- .get('/two')141- .expect('works', done);142- });143- })144- })127 128 describe('case sensitivity', function(){129 it('should be disabled by default', function(done){130 var app = express();5 unmodified lines136 request(app)137 .get('/USER')138 .expect('tj', done);139 })158- 140+141 describe('when "case sensitive routing" is enabled', function(){142 it('should match identical casing', function(done){143 var app = express();144 6 unmodified lines151 request(app)152 .get('/uSer')153 .expect('tj', done);154 })173- 155+156 it('should not match otherwise', function(done){157 var app = express();158 159 app.enable('case sensitive routing');20 unmodified lines180 request(app)181 .get('/user/')182 .expect('tj', done);183 })202- 184+185 describe('when "strict routing" is enabled', function(){186 it('should match trailing slashes', function(done){187 var app = express();188 6 unmodified lines195 request(app)196 .get('/user/')197 .expect('tj', done);198 })217- 199+200 it('should match no slashes', function(done){201 var app = express();202 203 app.enable('strict routing');5 unmodified lines209 request(app)210 .get('/user')211 .expect('tj', done);212 })231- 213+214 it('should fail when omitting the trailing slash', function(done){215 var app = express();216 217 app.enable('strict routing');5 unmodified lines223 request(app)224 .get('/user')225 .expect(404, done);226 })245- 227+228 it('should fail when adding the trailing slash', function(done){229 var app = express();230 231 app.enable('strict routing');24 unmodified lines256 .get('/user/tj')257 .expect(404, done);258 });259 })278- 260+261 it('should allow literal "."', function(done){262 var app = express();263 264 app.get('/api/users/:from..:to', function(req, res){19 unmodified lines284 request(app)285 .get('/user/tj.json')286 .expect('tj', done);287 })306- 288+289 it('should work with several', function(done){290 var app = express();291 292 app.get('/api/*.*', function(req, res){34 unmodified lines327 request(app)328 .get('/api/users/0.json')329 .expect('users/0.json', done);330 })349- 331+332 it('should not be greedy immediately after param', function(done){333 var app = express();334 335 app.get('/user/:user*', function(req, res){15 unmodified lines351 request(app)352 .get('/user/122/aaa')353 .expect('122', done);354 })373- 355+356 it('should span multiple segments', function(done){357 var app = express();358 359 app.get('/file/*', function(req, res){3 unmodified lines363 request(app)364 .get('/file/javascripts/jquery.js')365 .expect('javascripts/jquery.js', done);366 })385- 367+368 it('should be optional', function(done){369 var app = express();370 371 app.get('/file/*', function(req, res){3 unmodified lines375 request(app)376 .get('/file/')377 .expect('', done);378 })397- 379+380 it('should require a preceeding /', function(done){381 var app = express();382 383 app.get('/file/*', function(req, res){17 unmodified lines401 request(app)402 .get('/user/tj')403 .expect('tj', done);404 })423- 405+406 it('should match a single segment only', function(done){407 var app = express();408 409 app.get('/user/:user', function(req, res){3 unmodified lines413 request(app)414 .get('/user/tj/edit')415 .expect(404, done);416 })435- 417+418 it('should allow several capture groups', function(done){419 var app = express();420 421 app.get('/user/:user/:op', function(req, res){18 unmodified lines440 request(app)441 .get('/user/tj')442 .expect('viewing tj', done);443 })462- 444+445 it('should populate the capture group', function(done){446 var app = express();447 448 app.get('/user/:user/:op?', function(req, res){5 unmodified lines454 .get('/user/tj/edit')455 .expect('editing tj', done);456 })457 })476- 458+459 describe('.:name', function(){460 it('should denote a format', function(done){461 var app = express();462 9 unmodified lines472 .expect(404, done);473 });474 })475 })494- 476+477 describe('.:name?', function(){478 it('should denote an optional format', function(done){479 var app = express();480 9 unmodified lines490 .expect('foo as json', done);491 });492 })493 })512- 494+495 describe('when next() is called', function(){496 it('should continue lookup', function(done){497 var app = express()498 , calls = [];10 unmodified lines509 app.get('/foo', function(req, res, next){510 calls.push('/foo');511 next();512 });531- 513+514 app.get('/foo', function(req, res, next){515 calls.push('/foo 2');516 res.end('done');517 });5 unmodified lines523 done();524 })525 })526 })545- 527+528 describe('when next(err) is called', function(){529 it('should break out of app.router', function(done){530 var app = express()531 , calls = [];10 unmodified lines542 app.get('/foo', function(req, res, next){543 calls.push('/foo');544 next(new Error('fail'));545 });564- 546+547 app.get('/foo', function(req, res, next){548 assert(0);549 });550 36 unmodified lines