Skip to content
Myr

Added specs for param()

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent eee6926 · Browse files · 3 files+55 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+55 added−2 removed

  • tests:+40 added−0 removed
  • other:+15 added−2 removed

3 files+55 added−2 removed

modified:lib/express/core.js+6 added-1 removed
164 unmodified lines
165 */166 167 mapParams: function(route) {168 route.keys.each(function(key, i){169 this.request.params.path[key] = this.request.captures[++i]169 var val = this.request.captures[++i]170 if (key in Express.params)171 if ((val = Express.params[key].call(val, val)) === false)172 this.request.passed = true173 this.request.params.path[key] = val174 }, this)175 }176})177
145 unmodified lines
323 config: [],324 routes: [],325 plugins: [],326 settings: {},327 params: {},328 server: new Server329}330331// --- Defaults
22 unmodified lines
modified:lib/express/dsl.js+9 added-1 removed
modified:spec/spec.routing.js+40 added
2 unmodified lines
3 before_each4 reset()5 end6 7 describe 'param()'8 describe 'given no args'9 it 'should throw an error'10 -{ param() }.should.throw_error TypeError11 end12 end13 14 describe 'given a non-string as the first argument'15 it 'should throw an error'16 -{ param(12) }.should.throw_error TypeError17 end18 end19 20 describe 'given no callback function'21 it 'should throw an error'22 -{ param('foo') }.should.throw_error TypeError23 end24 end25 26 describe 'given a non-function as the second argument'27 it 'should throw an error'28 -{ param('foo', 2) }.should.throw_error TypeError29 end30 end31 32 describe 'with key / callback function'33 it 'should pre-process a value before it is passed to a route'34 param('user_id', function(val){35 val = parseInt(val)36 return isNaN(val) ? false : val37 })38 get('/user/:user_id', function(id){39 require('sys').p(id)40 return String(typeof id === 'number')41 })42 get('/user/12').body.should.eql 'true'43 end44 end45 end46 47 describe 'route'48 describe 'with callback function'49 it 'should respond with a body string'50 get('/user', function(){
307 unmodified lines