Skip to content
Myr

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

2 files+30 added−43 removed

modified:lib/application.js+5 added
400 unmodified lines
401methods.forEach(function(method){402 app[method] = function(path){403 if ('get' == method && 1 == arguments.length) return this.set(path);404405 // deprecated406 if (Array.isArray(path)) {407 console.trace('passing an array to app.VERB() is deprecated and will be removed in 4.0');408 }409410 // if no router attached yet, attach the router411 if (!this._usedRouter) this.use(this.router);412413 // setup route
123 unmodified lines
modified:test/app.router.js+25 added-43 removed
46 unmodified lines
47 app.use(function(req, res, next){48 calls.push('before');49 next();50 });51 5152 app.use(app.router);5354 app.use(function(req, res, next){55 calls.push('after');
11 unmodified lines
67 calls.should.eql(['before', 'GET /', 'after'])68 done();69 })70 })71 7172 it('should be auto .use()d on the first app.VERB() call', function(done){73 var app = express();7475 var calls = [];
1 unmodified line
77 app.use(function(req, res, next){78 calls.push('before');79 next();80 });81 8182 app.get('/', function(req, res, next){83 calls.push('GET /')84 next();85 });
22 unmodified lines
108 request(app)109 .get('/user/12?foo=bar')110 .expect('user', done);111 })112 112113 it('should populate req.params with the captures', function(done){114 var app = express();115116 app.get(/^\/user\/([0-9]+)\/(view|edit)?$/, function(req, res){
6 unmodified lines
123 .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 })127128 describe('case sensitivity', function(){129 it('should be disabled by default', function(done){130 var app = express();
5 unmodified lines
136 request(app)137 .get('/USER')138 .expect('tj', done);139 })158 140141 describe('when "case sensitive routing" is enabled', function(){142 it('should match identical casing', function(done){143 var app = express();144
6 unmodified lines
151 request(app)152 .get('/uSer')153 .expect('tj', done);154 })173 155156 it('should not match otherwise', function(done){157 var app = express();158159 app.enable('case sensitive routing');
20 unmodified lines
180 request(app)181 .get('/user/')182 .expect('tj', done);183 })202 184185 describe('when "strict routing" is enabled', function(){186 it('should match trailing slashes', function(done){187 var app = express();188
6 unmodified lines
195 request(app)196 .get('/user/')197 .expect('tj', done);198 })217 199200 it('should match no slashes', function(done){201 var app = express();202203 app.enable('strict routing');
5 unmodified lines
209 request(app)210 .get('/user')211 .expect('tj', done);212 })231 213214 it('should fail when omitting the trailing slash', function(done){215 var app = express();216217 app.enable('strict routing');
5 unmodified lines
223 request(app)224 .get('/user')225 .expect(404, done);226 })245 227228 it('should fail when adding the trailing slash', function(done){229 var app = express();230231 app.enable('strict routing');
24 unmodified lines
256 .get('/user/tj')257 .expect(404, done);258 });259 })278 260261 it('should allow literal "."', function(done){262 var app = express();263264 app.get('/api/users/:from..:to', function(req, res){
19 unmodified lines
284 request(app)285 .get('/user/tj.json')286 .expect('tj', done);287 })306 288289 it('should work with several', function(done){290 var app = express();291292 app.get('/api/*.*', function(req, res){
34 unmodified lines
327 request(app)328 .get('/api/users/0.json')329 .expect('users/0.json', done);330 })349 331332 it('should not be greedy immediately after param', function(done){333 var app = express();334335 app.get('/user/:user*', function(req, res){
15 unmodified lines
351 request(app)352 .get('/user/122/aaa')353 .expect('122', done);354 })373 355356 it('should span multiple segments', function(done){357 var app = express();358359 app.get('/file/*', function(req, res){
3 unmodified lines
363 request(app)364 .get('/file/javascripts/jquery.js')365 .expect('javascripts/jquery.js', done);366 })385 367368 it('should be optional', function(done){369 var app = express();370371 app.get('/file/*', function(req, res){
3 unmodified lines
375 request(app)376 .get('/file/')377 .expect('', done);378 })397 379380 it('should require a preceeding /', function(done){381 var app = express();382383 app.get('/file/*', function(req, res){
17 unmodified lines
401 request(app)402 .get('/user/tj')403 .expect('tj', done);404 })423 405406 it('should match a single segment only', function(done){407 var app = express();408409 app.get('/user/:user', function(req, res){
3 unmodified lines
413 request(app)414 .get('/user/tj/edit')415 .expect(404, done);416 })435 417418 it('should allow several capture groups', function(done){419 var app = express();420421 app.get('/user/:user/:op', function(req, res){
18 unmodified lines
440 request(app)441 .get('/user/tj')442 .expect('viewing tj', done);443 })462 444445 it('should populate the capture group', function(done){446 var app = express();447448 app.get('/user/:user/:op?', function(req, res){
5 unmodified lines
454 .get('/user/tj/edit')455 .expect('editing tj', done);456 })457 })476 458459 describe('.:name', function(){460 it('should denote a format', function(done){461 var app = express();462
9 unmodified lines
472 .expect(404, done);473 });474 })475 })494 476477 describe('.:name?', function(){478 it('should denote an optional format', function(done){479 var app = express();480
9 unmodified lines
490 .expect('foo as json', done);491 });492 })493 })512 494495 describe('when next() is called', function(){496 it('should continue lookup', function(done){497 var app = express()498 , calls = [];
10 unmodified lines
509 app.get('/foo', function(req, res, next){510 calls.push('/foo');511 next();512 });531 513514 app.get('/foo', function(req, res, next){515 calls.push('/foo 2');516 res.end('done');517 });
5 unmodified lines
523 done();524 })525 })526 })545 527528 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 lines
542 app.get('/foo', function(req, res, next){543 calls.push('/foo');544 next(new Error('fail'));545 });564 546547 app.get('/foo', function(req, res, next){548 assert(0);549 });550
36 unmodified lines