Skip to content
Myr

spec.request.js

This file

Path

spec/spec.request.js

394 lines · 13.1 KiB · JavaScript

Last changed by

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

History of this file

Take it

The walk stopped after 200 commits: lines older than fbf547d point at it.

Added Session classvisionmediabefore adoptionfbf547d

lines 1–13why, one step back
1
2describe 'Express'3 before_each4 reset()5 end6 7 describe 'Request'8 describe '#status()'9 it 'should set the response status'10 get('/user', function(){ this.status(500) })11 get('/user').status.should.eql 50012 end13 end

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 14–26why, one step back
14
15 describe '#charset'16 describe 'when defined'17 it 'should append "; charset=CHARSET'18 get('/user', function(){19 this.contentType('html')20 this.charset = 'UTF-8'21 return '∂'22 })23 get('/user').headers['Content-Type'].should.eql 'text/html; charset=UTF-8'24 end25 end26 end

Added Session classvisionmediabefore adoptionfbf547d

lines 27–54why, one step back
27
28 describe '#header()'29 describe 'when given a field name and value'30 it 'should set the header'31 get('/user', function(){32 this.header('x-foo', 'bar')33 })34 get('/user').headers.should.have_property 'x-foo', 'bar'35 end 36 end3738 describe 'when given a field name'39 it 'should return a request header value'40 get('/user', function(){41 return this.header('host')42 })43 get('/user').body.should.eql 'localhost'44 end4546 it 'should be case-insensitive'47 get('/user', function(){48 return this.header('Host')49 })50 get('/user').body.should.eql 'localhost'51 end52 end53 end54

Added Request#isXHR. Closes #229visionmediabefore adoption884d333

lines 55–71why, one step back
55 describe '#isXHR'
56 it 'should return false unless X-Requested-With is "XMLHttpRequest"'57 get('/', function(){ return this.isXHR ? 'yay' : 'nope' })58 get('/').body.should.eql 'nope'59 end60 61 it 'should return true when X-Requested-With is "XMLHttpRequest"'62 get('/', function(){ return this.isXHR ? 'yay' : 'nope' })63 get('/', { headers: { 'x-requested-with': 'XMLHttpRequest' }}).body.should.eql 'yay'64 end65 66 it 'should be case insensitive'67 get('/', function(){ return this.isXHR ? 'yay' : 'nope' })68 get('/', { headers: { 'x-requested-with': 'xmlhttprequest' }}).body.should.eql 'yay'69 end70 end71

Added Session classvisionmediabefore adoptionfbf547d

lines 72–87why, one step back
72 describe '#accepts()'
73 describe 'when the Accept header is present'74 it 'should return true if the mime type is acceptable'75 get('/user', function(){ return this.accepts('jpeg').toString() })76 get('/user', { headers: { accept: 'image/jpeg' }}).body.should.eql 'true'77 end78 79 it 'should return false if the mime type is not present'80 get('/user', function(){ return this.accepts('html').toString() })81 get('/user', { headers: { accept: 'image/jpeg' }}).body.should.eql 'false'82 end83 end84 85 describe 'when the Accept header is not present'86 it 'should return true'87 get('/user', function(){ return this.accepts('jpeg').toString() })

Removed utils.mixin() use Object#mergeDeep()visionmediabefore adoption33277c3

line 88why, one step back
88 get('/user', { headers: { accept: '' }}).body.should.eql 'true'

Added Session classvisionmediabefore adoptionfbf547d

lines 89–90why, one step back
89 end
90 end

Merge branch 'integration'visionmediabefore adoption406a7f4

lines 91–113why, one step back
91
92 describe 'should allow multiple arguments'93 it 'should return true if any mime type is present'94 get('/user', function(){ return this.accepts('jpeg', 'png').toString() })95 get('/user', { headers: { accept: 'image/gif,image/png' }}).body.should.eql 'true'96 end97 98 it 'should return false if none of the mime types are present'99 get('/user', function(){ return this.accepts('jpeg', 'png').toString() })100 get('/user', { headers: { accept: 'text/plain,text/html' }}).body.should.eql 'false'101 end102 end103 104 describe 'when a media type range was sent'105 it 'should return true if the group media type matches'106 get('/user', function(){ return this.accepts('html').toString() })107 get('/user', { headers: { accept: 'text/plain,text/*' }}).body.should.eql 'true'108 end109 it 'should return false if the group media type does not match'110 get('/user', function(){ return this.accepts('ogg').toString() })111 get('/user', { headers: { accept: 'text/plain,text/*' }}).body.should.eql 'false'112 end113 end

Added Session classvisionmediabefore adoptionfbf547d

lines 114–121why, one step back
114 end
115 116 describe '#contentType()'117 it 'should set Content-Type header with mime type passed'118 get('/style.css', function(){119 this.contentType('css')120 return 'body { background: white; }'121 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 122why, one step back
122 get('/style.css').headers['Content-Type'].should.eql 'text/css'

Added Session classvisionmediabefore adoptionfbf547d

lines 123–131why, one step back
123 end
124 end125 126 describe '#attachment()'127 it 'should set Content-Disposition to attachment'128 get('/report', function(){129 this.attachment()130 return 'foo'131 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 132why, one step back
132 get('/report').headers['Content-Disposition'].should.eql 'attachment'

Added Session classvisionmediabefore adoptionfbf547d

lines 133–139why, one step back
133 end
134135 it 'should set attachment filename'136 get('/report', function(){137 this.attachment('report.pdf')138 return 'foo'139 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 140why, one step back
140 get('/report').headers['Content-Disposition'].should.eql 'attachment; filename="report.pdf"'

Added Session classvisionmediabefore adoptionfbf547d

lines 141–191why, one step back
141 end
142 end143144 describe '#param()'145 it 'should return a route placeholder value'146 get('/user/:id', function(){147 return 'user ' + this.param('id')148 })149 get('/user/12').body.should.eql 'user 12'150 end151152 it 'should return several route placeholder values'153 get('/user/:id/:operation', function(){154 return this.param('operation') + 'ing user ' + this.param('id') 155 })156 get('/user/12/edit').body.should.eql 'editing user 12'157 end158159 it 'should allow optional placeholders'160 get('/user/:id?', function(){161 return this.param('id') ? 'user ' + this.param('id') : 'users'162 })163 get('/user/12').body.should.eql 'user 12'164 get('/user').body.should.eql 'users'165 end166167 it 'should allow placeholders as part of a segment'168 get('/report.:format', function(){169 return 'report as ' + this.param('format')170 })171 get('/report.csv').body.should.eql 'report as csv'172 get('/report.pdf').body.should.eql 'report as pdf'173 end174175 it 'should allow optional placeholders in middle segments'176 get('/user/:id?/edit', function(){177 return this.param('id') ? 'editing ' + this.param('id') : 'editing your account'178 })179 get('/user/12/edit').body.should.eql 'editing 12'180 get('/user/edit').body.should.eql 'editing your account'181 end182183 it 'should work with several routes'184 get('/user/:id', function(){ return this.param('id') })185 get('/product/:name', function(){ return this.param('name') })186 get('/user/12').body.should.eql '12'187 get('/product/ipod').body.should.eql 'ipod'188 end189190 it 'should work with a query string'191 get('/user', function(){

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 192–193why, one step back
192 var page = this.param('page')
193 return page === undefined ? 'First page' : String(page)

Added Session classvisionmediabefore adoptionfbf547d

lines 194–195why, one step back
194 })
195 get('/user').body.should.eql 'First page'

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 196why, one step back
196 get('/user?page=0').body.should.eql '0'

Added Session classvisionmediabefore adoptionfbf547d

lines 197–206why, one step back
197 get('/user?page=2').body.should.eql '2'
198 get('/user?foo[]=bar&page=5').body.should.eql '5'199 end200201 it 'should work with splats'202 get('/:path/*.*', function(path, file, ext){203 return [path, file, ext].join(', ')204 })205 get('/public/app.js').body.should.eql 'public, app, js'206 end

Merge branch 'pull'visionmediabefore adoptionf008af0

lines 207–210why, one step back
207 end
208 209 describe '#pass()'210 it 'should pass control to the next matching route'

Request#pass() accepts a pathname stringvisionmediabefore adoption300cfe7

line 211why, one step back
211 get('/user', function(){

Merge branch 'pull'visionmediabefore adoptionf008af0

lines 212–213why, one step back
212 this.pass()
213 })

Request#pass() accepts a pathname stringvisionmediabefore adoption300cfe7

line 214why, one step back
214 get('/user', function(){

Merge branch 'pull'visionmediabefore adoptionf008af0

lines 215–217why, one step back
215 this.pass()
216 return 'nodejs'217 })

Request#pass() accepts a pathname stringvisionmediabefore adoption300cfe7

line 218why, one step back
218 get('/user', function(){ return 'success'})

Merge branch 'pull'visionmediabefore adoptionf008af0

lines 219–220why, one step back
219 get('/user').body.should.eql 'success'
220 end

Request#pass() accepts a pathname stringvisionmediabefore adoption300cfe7

lines 221–233why, one step back
221
222 describe 'given a string'223 it 'should pass to the given route'224 get('/user', function(){225 this.pass('/user/1')226 })227 get('/user/:id', function(){228 return 'Supa doopa usa'229 })230 get('/user').body.should.eql 'Supa doopa usa'231 end232 end233 end

Added specs for Request#error()visionmediabefore adoption6047cd4

lines 234–235why, one step back
234
235 describe '#error()'

Added DSL level error() route supportvisionmediabefore adoptionb958393

lines 236–237why, one step back
236 describe 'when an error route is defined'
237 it 'should be called'

error() is passed the exceptionvisionmediabefore adoption1c0e2ce

line 238why, one step back
238 var err

Added DSL level error() route supportvisionmediabefore adoptionb958393

line 239why, one step back
239 disable('throw exceptions')

error() is passed the exceptionvisionmediabefore adoption1c0e2ce

lines 240–241why, one step back
240 global.error(function(e){
241 err = e

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 242why, one step back
242 this.respond(500, 'FAIL!')

Added DSL level error() route supportvisionmediabefore adoptionb958393

lines 243–245why, one step back
243 })
244 get('/', function(){ this.error(new Error('whoop')) })245 get('/').body.should.eql 'FAIL!'

error() is passed the exceptionvisionmediabefore adoption1c0e2ce

line 246why, one step back
246 err.message.should.eql 'whoop'

Added DSL level error() route supportvisionmediabefore adoptionb958393

lines 247–249why, one step back
247 end
248 end249

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 250–262why, one step back
250 describe 'when not accepting common mime types'
251 it 'should render the default 500 status body'252 var headers = { headers: { accept: 'text/xml' }}253 disable('throw exceptions')254 enable('show exceptions')255 get('/', function(){256 this.error(new Error('fail!'))257 })258 get('/', headers).body.should.eql 'Internal Server Error'259 get('/', headers).status.should.eql 500260 end261 end262

Added specs for Request#error()visionmediabefore adoption6047cd4

lines 263–273why, one step back
263 describe 'when accepting "html"'
264 describe 'with "show exceptions" enabled'265 it 'should render the show-exceptions page'266 disable('throw exceptions')267 enable('show exceptions')268 get('/', function(){269 this.error(new Error('fail!'))270 })271 get('/').body.should.include '<em>500</em> Error: fail!'272 get('/').status.should.eql 500273 end

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 274–275why, one step back
274
275 it 'should render the show-exceptions page with errors thrown within the route'

Added specs for Request#error()visionmediabefore adoption6047cd4

lines 276–278why, one step back
276 disable('throw exceptions')
277 enable('show exceptions')278 get('/', function(){

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 279why, one step back
279 throw new Error('fail!')

Added specs for Request#error()visionmediabefore adoption6047cd4

line 280why, one step back
280 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 281–282why, one step back
281 get('/').body.should.include '<em>500</em> Error: fail!'
282 get('/').status.should.eql 500

Added specs for Request#error()visionmediabefore adoption6047cd4

lines 283–284why, one step back
283 end
284 end

More Request#error() specsvisionmediabefore adoption54fa643

lines 285–295why, one step back
285
286 describe 'with "throw exceptions" enabled'287 it 'should re-throw the exception'288 enable('show exceptions')289 enable('throw exceptions')290 get('/', function(){291 this.error(new Error('fail!'))292 })293 -{ get('/') }.should.throw_error Error, 'fail!'294 end295 end

Added specs for Request#error()visionmediabefore adoption6047cd4

lines 296–297why, one step back
296 end
297

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 298–325why, one step back
298 describe 'when accepting "text/plain"'
299 describe 'with "show exceptions" enabled'300 it 'should render a text representation of the error'301 disable('throw exceptions')302 enable('show exceptions')303 get('/', function(){304 this.error(new Error('fail!'))305 })306 get('/', { headers: { accept: 'text/plain' }}).body.should.include '500 Error: fail!'307 get('/').status.should.eql 500308 end309 end310 end311 312 describe 'when accepting "application/json"'313 describe 'with "show exceptions" enabled'314 it 'should render a text representation of the error'315 disable('throw exceptions')316 enable('show exceptions')317 get('/', function(){318 this.error(new Error('fail!'))319 })320 get('/', { headers: { accept: 'application/json' }}).body.should.include '{"error":{"message":"fail!"'321 get('/').status.should.eql 500 322 end323 end324 end325

Added specs for Request#error()visionmediabefore adoption6047cd4

lines 326–333why, one step back
326 describe 'with "show exceptions" disabled'
327 it 'should render the default 500 status body'328 disable('throw exceptions')329 get('/', function(){330 this.error(new Error('fail!'))331 })332 get('/').body.should.eql 'Internal Server Error'333 get('/').status.should.eql 500

More Request#error() specsvisionmediabefore adoption54fa643

lines 334–343why, one step back
334 end
335 end336 337 describe 'with "throw exceptions" enabled'338 it 'should re-throw the exception'339 enable('throw exceptions')340 get('/', function(){341 this.error(new Error('fail!'))342 })343 -{ get('/') }.should.throw_error Error, 'fail!'

Added specs for Request#error()visionmediabefore adoption6047cd4

lines 344–346why, one step back
344 end
345 end346 end

Added specs for Request#notFound()visionmediabefore adoptiona4833e7

lines 347–348why, one step back
347
348 describe '#notFound()'

Added DSL level notFound() route supportvisionmediabefore adoptiona6dd697

lines 349–351why, one step back
349 describe 'when a notFound route is defined'
350 it 'should be called'351 notFound(function(){

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 352why, one step back
352 this.respond(404, 'Sorry your page was not found')

Added DSL level notFound() route supportvisionmediabefore adoptiona6dd697

lines 353–358why, one step back
353 })
354 get('/', function(){ this.notFound() })355 get('/').body.should.eql 'Sorry your page was not found'356 end357 end358

Added specs for Request#notFound()visionmediabefore adoptiona4833e7

lines 359–391why, one step back
359 describe 'when accepting "html"'
360 describe 'with "helpful 404" enabled'361 it 'should render the not-found page'362 enable('helpful 404')363 get('/', function(){ this.notFound() })364 get('/').body.should.include '<em>404</em> Not Found'365 get('/').status.should.eql 404366 end367 end368 end369 370 describe 'when not accepting "html"'371 describe 'with "helpful 404" enabled'372 it 'should render defaulat 404 status body'373 var headers = { headers: { accept: 'text/plain' }}374 enable('helpful 404')375 get('/', function(){ this.notFound() })376 get('/', headers).body.should.eql 'Not Found'377 get('/', headers).status.should.eql 404378 end379 end380 end381 382 describe 'when "helpful 404" is disabled'383 it 'should render defaulat 404 status body'384 var headers = { headers: { accept: 'text/plain' }}385 enable('helpful 404')386 get('/', function(){ this.notFound() })387 get('/', headers).body.should.eql 'Not Found'388 get('/', headers).status.should.eql 404389 end390 end391 end

Request#pass() accepts a pathname stringvisionmediabefore adoption300cfe7

line 392why, one step back
392

Added Session classvisionmediabefore adoptionfbf547d

lines 393–394why, one step back
393 end
394end