Skip to content
Myr

spec.request.js

This file

Path

spec/spec.request.js

369 lines · 12.2 KiB · JavaScript

Last changed by

Merge branch 'fix-querystring-0'visionmediabefore adoption7cf18c0

History of this file

Take it

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

Removed Route#run(). Closes #188visionmediabefore adoption4d1bda0

lines 1–41why, 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 end1415 describe '#header()'16 describe 'when given a field name and value'17 it 'should set the header'18 get('/user', function(){19 this.header('x-foo', 'bar')20 })21 get('/user').headers.should.have_property 'x-foo', 'bar'22 end 23 end2425 describe 'when given a field name'26 it 'should return a request header value'27 get('/user', function(){28 return this.header('host')29 })30 get('/user').body.should.eql 'localhost'31 end3233 it 'should be case-insensitive'34 get('/user', function(){35 return this.header('Host')36 })37 get('/user').body.should.eql 'localhost'38 end39 end40 end41

Added Request#isXHR. Closes #229visionmediabefore adoption884d333

lines 42–58why, one step back
42 describe '#isXHR'
43 it 'should return false unless X-Requested-With is "XMLHttpRequest"'44 get('/', function(){ return this.isXHR ? 'yay' : 'nope' })45 get('/').body.should.eql 'nope'46 end47 48 it 'should return true when X-Requested-With is "XMLHttpRequest"'49 get('/', function(){ return this.isXHR ? 'yay' : 'nope' })50 get('/', { headers: { 'x-requested-with': 'XMLHttpRequest' }}).body.should.eql 'yay'51 end52 53 it 'should be case insensitive'54 get('/', function(){ return this.isXHR ? 'yay' : 'nope' })55 get('/', { headers: { 'x-requested-with': 'xmlhttprequest' }}).body.should.eql 'yay'56 end57 end58

Removed Route#run(). Closes #188visionmediabefore adoption4d1bda0

lines 59–74why, one step back
59 describe '#accepts()'
60 describe 'when the Accept header is present'61 it 'should return true if the mime type is acceptable'62 get('/user', function(){ return this.accepts('jpeg').toString() })63 get('/user', { headers: { accept: 'image/jpeg' }}).body.should.eql 'true'64 end65 66 it 'should return false if the mime type is not present'67 get('/user', function(){ return this.accepts('html').toString() })68 get('/user', { headers: { accept: 'image/jpeg' }}).body.should.eql 'false'69 end70 end71 72 describe 'when the Accept header is not present'73 it 'should return true'74 get('/user', function(){ return this.accepts('jpeg').toString() })

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

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

Removed Route#run(). Closes #188visionmediabefore adoption4d1bda0

lines 76–77why, one step back
76 end
77 end

Merge branch 'integration'visionmediabefore adoption406a7f4

lines 78–100why, one step back
78
79 describe 'should allow multiple arguments'80 it 'should return true if any mime type is present'81 get('/user', function(){ return this.accepts('jpeg', 'png').toString() })82 get('/user', { headers: { accept: 'image/gif,image/png' }}).body.should.eql 'true'83 end84 85 it 'should return false if none of the mime types are present'86 get('/user', function(){ return this.accepts('jpeg', 'png').toString() })87 get('/user', { headers: { accept: 'text/plain,text/html' }}).body.should.eql 'false'88 end89 end90 91 describe 'when a media type range was sent'92 it 'should return true if the group media type matches'93 get('/user', function(){ return this.accepts('html').toString() })94 get('/user', { headers: { accept: 'text/plain,text/*' }}).body.should.eql 'true'95 end96 it 'should return false if the group media type does not match'97 get('/user', function(){ return this.accepts('ogg').toString() })98 get('/user', { headers: { accept: 'text/plain,text/*' }}).body.should.eql 'false'99 end100 end

Removed Route#run(). Closes #188visionmediabefore adoption4d1bda0

lines 101–204why, one step back
101 end
102 103 describe '#halt()'104 describe 'when given no arguments'105 it 'should respond with 404 Not Found'106 get('/user', function(){ this.halt() })107 get('/user').status.should.eql 404108 get('/user').body.should.include('Not Found')109 end110 end111112 describe 'when given a status code'113 it 'should respond with that status and its associated default body'114   get('/user', function(){ this.halt(400) })115   get('/user').status.should.eql 400116   get('/user').body.should.include('Bad Request')117 end118 end119120 describe 'when given a status code and body'121 it 'should respond with the status and its body'122 get('/user', function(){ this.halt(400, 'Oh noes!') })123 get('/user').status.should.eql 400124 get('/user').body.should.include('Oh noes!')125 end126 end127 end128129 describe '#contentType()'130 it 'should set Content-Type header with mime type passed'131 get('/style.css', function(){132 this.contentType('css')133 return 'body { background: white; }'134 })135 get('/style.css').headers['content-type'].should.eql 'text/css'136 end137 end138 139 describe '#attachment()'140 it 'should set Content-Disposition to attachment'141 get('/report', function(){142 this.attachment()143 return 'foo'144 })145 get('/report').headers['content-disposition'].should.eql 'attachment'146 end147148 it 'should set attachment filename'149 get('/report', function(){150 this.attachment('report.pdf')151 return 'foo'152 })153 get('/report').headers['content-disposition'].should.eql 'attachment; filename="report.pdf"'154 end155 end156157 describe '#param()'158 it 'should return a route placeholder value'159 get('/user/:id', function(){160 return 'user ' + this.param('id')161 })162 get('/user/12').body.should.eql 'user 12'163 end164165 it 'should return several route placeholder values'166 get('/user/:id/:operation', function(){167 return this.param('operation') + 'ing user ' + this.param('id') 168 })169 get('/user/12/edit').body.should.eql 'editing user 12'170 end171172 it 'should allow optional placeholders'173 get('/user/:id?', function(){174 return this.param('id') ? 'user ' + this.param('id') : 'users'175 })176 get('/user/12').body.should.eql 'user 12'177 get('/user').body.should.eql 'users'178 end179180 it 'should allow placeholders as part of a segment'181 get('/report.:format', function(){182 return 'report as ' + this.param('format')183 })184 get('/report.csv').body.should.eql 'report as csv'185 get('/report.pdf').body.should.eql 'report as pdf'186 end187188 it 'should allow optional placeholders in middle segments'189 get('/user/:id?/edit', function(){190 return this.param('id') ? 'editing ' + this.param('id') : 'editing your account'191 })192 get('/user/12/edit').body.should.eql 'editing 12'193 get('/user/edit').body.should.eql 'editing your account'194 end195196 it 'should work with several routes'197 get('/user/:id', function(){ return this.param('id') })198 get('/product/:name', function(){ return this.param('name') })199 get('/user/12').body.should.eql '12'200 get('/product/ipod').body.should.eql 'ipod'201 end202203 it 'should work with a query string'204 get('/user', function(){

Merge branch 'fix-querystring-0'visionmediabefore adoption7cf18c0

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

Removed Route#run(). Closes #188visionmediabefore adoption4d1bda0

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

Merge branch 'fix-querystring-0'visionmediabefore adoption7cf18c0

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

Removed Route#run(). Closes #188visionmediabefore adoption4d1bda0

lines 210–219why, one step back
210 get('/user?page=2').body.should.eql '2'
211 get('/user?foo[]=bar&page=5').body.should.eql '5'212 end213214 it 'should work with splats'215 get('/:path/*.*', function(path, file, ext){216 return [path, file, ext].join(', ')217 })218 get('/public/app.js').body.should.eql 'public, app, js'219 end

Merge branch 'pull'visionmediabefore adoptionf008af0

lines 220–223why, one step back
220 end
221 222 describe '#pass()'223 it 'should pass control to the next matching route'

Request#pass() accepts a pathname stringvisionmediabefore adoption300cfe7

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

Merge branch 'pull'visionmediabefore adoptionf008af0

lines 225–226why, one step back
225 this.pass()
226 })

Request#pass() accepts a pathname stringvisionmediabefore adoption300cfe7

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

Merge branch 'pull'visionmediabefore adoptionf008af0

lines 228–230why, one step back
228 this.pass()
229 return 'nodejs'230 })

Request#pass() accepts a pathname stringvisionmediabefore adoption300cfe7

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

Merge branch 'pull'visionmediabefore adoptionf008af0

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

Request#pass() accepts a pathname stringvisionmediabefore adoption300cfe7

lines 234–246why, one step back
234
235 describe 'given a string'236 it 'should pass to the given route'237 get('/user', function(){238 this.pass('/user/1')239 })240 get('/user/:id', function(){241 return 'Supa doopa usa'242 })243 get('/user').body.should.eql 'Supa doopa usa'244 end245 end246 end

Added specs for Request#error()visionmediabefore adoption6047cd4

lines 247–248why, one step back
247
248 describe '#error()'

Added DSL level error() route supportvisionmediabefore adoptionb958393

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

error() is passed the exceptionvisionmediabefore adoption1c0e2ce

line 251why, one step back
251 var err

Added DSL level error() route supportvisionmediabefore adoptionb958393

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

error() is passed the exceptionvisionmediabefore adoption1c0e2ce

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

Added DSL level error() route supportvisionmediabefore adoptionb958393

lines 255–258why, one step back
255 this.halt(500, 'FAIL!')
256 })257 get('/', function(){ this.error(new Error('whoop')) })258 get('/').body.should.eql 'FAIL!'

error() is passed the exceptionvisionmediabefore adoption1c0e2ce

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

Added DSL level error() route supportvisionmediabefore adoptionb958393

lines 260–262why, one step back
260 end
261 end262

Added specs for Request#error()visionmediabefore adoption6047cd4

lines 263–287why, 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 end274 end275 276 describe 'when not accepting "html"'277 it 'should render the default 500 status body'278 var headers = { headers: { accept: 'text/plain' }}279 disable('throw exceptions')280 enable('show exceptions')281 get('/', function(){282 this.error(new Error('fail!'))283 })284 get('/', headers).body.should.eql 'Internal Server Error'285 get('/', headers).status.should.eql 500286 end287 end

More Request#error() specsvisionmediabefore adoption54fa643

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

Added specs for Request#error()visionmediabefore adoption6047cd4

lines 299–308why, one step back
299 end
300 301 describe 'with "show exceptions" disabled'302 it 'should render the default 500 status body'303 disable('throw exceptions')304 get('/', function(){305 this.error(new Error('fail!'))306 })307 get('/').body.should.eql 'Internal Server Error'308 get('/').status.should.eql 500

More Request#error() specsvisionmediabefore adoption54fa643

lines 309–318why, one step back
309 end
310 end311 312 describe 'with "throw exceptions" enabled'313 it 'should re-throw the exception'314 enable('throw exceptions')315 get('/', function(){316 this.error(new Error('fail!'))317 })318 -{ get('/') }.should.throw_error Error, 'fail!'

Added specs for Request#error()visionmediabefore adoption6047cd4

lines 319–321why, one step back
319 end
320 end321 end

Added specs for Request#notFound()visionmediabefore adoptiona4833e7

lines 322–323why, one step back
322
323 describe '#notFound()'

Added DSL level notFound() route supportvisionmediabefore adoptiona6dd697

lines 324–333why, one step back
324 describe 'when a notFound route is defined'
325 it 'should be called'326 notFound(function(){327 this.halt(404, 'Sorry your page was not found')328 })329 get('/', function(){ this.notFound() })330 get('/').body.should.eql 'Sorry your page was not found'331 end332 end333

Added specs for Request#notFound()visionmediabefore adoptiona4833e7

lines 334–366why, one step back
334 describe 'when accepting "html"'
335 describe 'with "helpful 404" enabled'336 it 'should render the not-found page'337 enable('helpful 404')338 get('/', function(){ this.notFound() })339 get('/').body.should.include '<em>404</em> Not Found'340 get('/').status.should.eql 404341 end342 end343 end344 345 describe 'when not accepting "html"'346 describe 'with "helpful 404" enabled'347 it 'should render defaulat 404 status body'348 var headers = { headers: { accept: 'text/plain' }}349 enable('helpful 404')350 get('/', function(){ this.notFound() })351 get('/', headers).body.should.eql 'Not Found'352 get('/', headers).status.should.eql 404353 end354 end355 end356 357 describe 'when "helpful 404" is disabled'358 it 'should render defaulat 404 status body'359 var headers = { headers: { accept: 'text/plain' }}360 enable('helpful 404')361 get('/', function(){ this.notFound() })362 get('/', headers).body.should.eql 'Not Found'363 get('/', headers).status.should.eql 404364 end365 end366 end

Request#pass() accepts a pathname stringvisionmediabefore adoption300cfe7

line 367why, one step back
367

Removed Route#run(). Closes #188visionmediabefore adoption4d1bda0

lines 368–369why, one step back
368 end
369end