view.test.js
This file
Path
test/view.test.js
887 lines · 22.6 KiB · JavaScript
Last changed by
dont change NODE_ENV in testsTj Holowaychukbefore adoptionce47f96
History of this fileTake it
The walk stopped after 200 commits: lines older than c24a6b2 point at it.
Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 1–9why, one step back12/**3 * Module dependencies.4 */56var express = require('express')7 , connect = require('connect')8 , assert = require('assert')9 , should = require('should')moved files from lib/express/* to lib/Tj Holowaychukbefore adoption3d597a5
line 10why, one step back10 , View = require('../lib/view')Removed Partial constructor (not used)Tj Holowaychukbefore adoptiond7488bb
line 11why, one step back11 , partial = require('../lib/view/partial')Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 12–95why, one step back1213/**14 * Create a test server with views set to ./fixtures.15 */1617var create = function(){18 var app = express.createServer.apply(express, arguments);19 app.set('views', __dirname + '/fixtures');20 return app;21};2223module.exports = {24 'test View#path': function(){25 var view = new View('forum/thread.ejs', { root: '/www/mysite/views' });26 view.path.should.equal('/www/mysite/views/forum/thread.ejs');2728 var view = new View('/www/mysite/views/path.ejs');29 view.path.should.equal('/www/mysite/views/path.ejs');3031 var view = new View('user', { parentView: view });32 view.path.should.equal('/www/mysite/views/user.ejs');3334 var view = new View('user/list', { parentView: view });35 view.path.should.equal('/www/mysite/views/user/list.ejs');3637 var view = new View('user.jade', { parentView: new View('foo', { root: '/bar' }) });38 view.path.should.equal('/bar/user.jade');3940 var view = new View('/foo.bar.baz/user.ejs');41 view.path.should.equal('/foo.bar.baz/user.ejs');42 43 var view = new View('/foo.bar.baz/user', { parentView: view });44 view.path.should.equal('/foo.bar.baz/user.ejs');4546 var view = new View('user', { parentView: view });47 view.path.should.equal('/foo.bar.baz/user.ejs');48 },49 50 'test View#engine': function(){51 var view = new View('/absolute/path.ejs');52 view.engine.should.equal('ejs');5354 var view = new View('user', { parentView: view });55 view.engine.should.equal('ejs');5657 var view = new View('/user', { defaultEngine: 'jade' });58 view.engine.should.equal('jade');5960 var view = new View('/foo.bar/user.ejs');61 view.engine.should.equal('ejs');62 },63 64 'test View#extension': function(){65 var view = new View('/absolute/path.ejs');66 view.extension.should.equal('.ejs');6768 var view = new View('user', { parentView: view });69 view.extension.should.equal('.ejs');7071 var view = new View('/user', { defaultEngine: 'jade' });72 view.extension.should.equal('.jade');7374 var view = new View('/foo.bar/user.ejs');75 view.extension.should.equal('.ejs');76 },77 78 'test View#dirname': function(){79 var view = new View('/absolute/path.ejs');80 view.dirname.should.equal('/absolute');8182 var view = new View('user', { parentView: view });83 view.dirname.should.equal('/absolute');84 },85 86 'test View#contents': function(){87 var view = new View(__dirname + '/fixtures/hello.jade');88 view.contents.should.equal('p :(');89 },90 91 'test View#templateEngine': function(){92 var view = new View(__dirname + '/fixtures/hello.jade');93 view.templateEngine.should.equal(require('jade'));94 },95 Removed Partial constructor (not used)Tj Holowaychukbefore adoptiond7488bb
lines 96–97why, one step back96 'test partial.resolveObjectName()': function(){97 var resolve = partial.resolveObjectName;Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 98–116why, one step back98 resolve('/path/to/user.ejs').should.equal('user');99 resolve('/path/to/user-post.ejs').should.equal('userPost');100 resolve('/path/to/user post.ejs').should.equal('userPost');101 resolve('forum thread post.ejs').should.equal('forumThreadPost');102 resolve('forum thread post.ejs').should.equal('forumThreadPost');103 },104 105 'test #render()': function(){106 var app = create();107 app.set('view engine', 'jade');108109 app.get('/', function(req, res){110 res.render('index.jade', { layout: false });111 });112113 app.get('/jade', function(req, res){114 res.render('index', { layout: false });115 });116haml working fineTj Holowaychukbefore adoptiondfdbbb5
lines 117–119why, one step back117 app.get('/haml', function(req, res){118 res.render('hello.haml', { layout: false });119 });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 120–134why, one step back120121 app.get('/callback/layout/no-options', function(req, res){122 res.render('hello.jade', function(err, str){123 assert.ok(!err);124 res.send(str.replace(':(', ':)'));125 });126 });127128 app.get('/callback/layout', function(req, res){129 res.render('hello.jade', {}, function(err, str){130 assert.ok(!err);131 res.send(str.replace(':(', ':)'));132 });133 });134haml working fineTj Holowaychukbefore adoptiondfdbbb5
lines 135–140why, one step back135 app.get('/callback', function(req, res){136 res.render('hello.haml', { layout: false }, function(err, str){137 assert.ok(!err);138 res.send(str.replace('Hello World', ':)'));139 });140 });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 141–158why, one step back141142 app.get('/invalid', function(req, res){143 res.render('invalid.jade', { layout: false });144 });145146 app.get('/invalid-async', function(req, res){147 process.nextTick(function(){148 res.render('invalid.jade', { layout: false });149 });150 });151152 app.get('/error', function(req, res){153 res.render('invalid.jade', { layout: false }, function(err){154 res.send(err.arguments[0]);155 });156 });157158 app.get('/absolute', function(req, res){Added index view testTj Holowaychukbefore adoption97b8e75
line 159why, one step back159 res.render(__dirname + '/fixtures/index.jade', { layout: false });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 160–161why, one step back160 });161Added index view testTj Holowaychukbefore adoption97b8e75
line 162why, one step back162 app.get('/ferret', function(req, res){Added partial() index testTj Holowaychukbefore adoptiond70fee7
line 163why, one step back163 res.render('ferret', { layout: false, ferret: { name: 'Tobi' }});Added index view testTj Holowaychukbefore adoption97b8e75
lines 164–165why, one step back164 });165Added res.render() status support backTj Holowaychukbefore adoptiond152e7e
lines 166–172why, one step back166 app.get('/status', function(req, res){167 res.render('hello.jade', { status: 500 });168 });169170 assert.response(app,171 { url: '/status' },172 { status: 500 });Added index view testTj Holowaychukbefore adoption97b8e75
lines 173–175why, one step back173 assert.response(app,174 { url: '/ferret' },175 { body: '<li class="ferret">Tobi</li>' });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 176–177why, one step back176 assert.response(app,177 { url: '/' },Changed; charsets are no longer impliedTj Holowaychukbefore adoption9fc3499
line 178why, one step back178 { body: '<p>Welcome</p>', headers: { 'Content-Type': 'text/html' }});Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 179–184why, one step back179 assert.response(app,180 { url: '/jade' },181 { body: '<p>Welcome</p>' });182 assert.response(app,183 { url: '/absolute' },184 { body: '<p>Welcome</p>' });haml working fineTj Holowaychukbefore adoptiondfdbbb5
lines 185–190why, one step back185 assert.response(app,186 { url: '/haml' },187 { body: '\n<p>Hello World</p>' });188 assert.response(app,189 { url: '/callback' },190 { body: '\n<p>:)</p>' });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 191–267why, one step back191 assert.response(app,192 { url: '/callback/layout' },193 { body: '<html><body><p>:)</p></body></html>' });194 assert.response(app,195 { url: '/callback/layout/no-options' },196 { body: '<html><body><p>:)</p></body></html>' });197 assert.response(app,198 { url: '/error' },199 { body: 'doesNotExist' });200 assert.response(app,201 { url: '/invalid' },202 function(res){203 assert.ok(res.body.indexOf('ReferenceError') >= 0);204 assert.ok(res.body.indexOf('doesNotExist') >= 0);205 });206 assert.response(app,207 { url: '/invalid-async' },208 function(res){209 assert.ok(res.body.indexOf('ReferenceError') >= 0);210 assert.ok(res.body.indexOf('doesNotExist') >= 0);211 });212 },213 214 'test #render() layout': function(){215 var app = create();216 app.set('view engine', 'jade');217218 app.get('/', function(req, res){219 res.render('index.jade');220 });221 app.get('/jade', function(req, res){222 res.render('index');223 });224225 assert.response(app,226 { url: '/' },227 { body: '<html><body><p>Welcome</p></body></html>' });228 },229 230 'test #render() specific layout': function(beforeExit){231 var app = create()232 , called;233234 app.get('/', function(req, res){235 res.render('index.jade', { layout: 'cool-layout.jade' }, function(err, html){236 called = true;237 res.send(html);238 });239 });240 app.get('/no-ext', function(req, res){241 res.render('index.jade', { layout: 'cool-layout' });242 });243 app.get('/relative', function(req, res){244 res.render('index.jade', { layout: 'layouts/foo.jade' });245 });246 app.get('/absolute', function(req, res){247 res.render('index.jade', { layout: __dirname + '/fixtures/layouts/foo.jade' });248 });249 app.get('/nope', function(req, res){250 res.render('index.jade', { layout: 'nope.jade' });251 });252253 assert.response(app,254 { url: '/' },255 { body: '<cool><p>Welcome</p></cool>' });256 assert.response(app,257 { url: '/no-ext' },258 { body: '<cool><p>Welcome</p></cool>' });259 assert.response(app,260 { url: '/relative' },261 { body: '<foo></foo>' });262 assert.response(app,263 { url: '/absolute' },264 { body: '<foo></foo>' });265 assert.response(app,266 { url: '/nope' },267 function(res){Added view resolution hints when in developmentTj Holowaychukbefore adoptionf1f1261
line 268why, one step back268 assert.ok(~res.body.indexOf('Error: failed to locate view'));fixed a testTj Holowaychukbefore adoption71e1bcd
line 269why, one step back269 assert.ok(~res.body.indexOf('nope'));Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 270–289why, one step back270 });271272 beforeExit(function(){273 assert.ok(called, 'Layout callback never called'); 274 });275 },276 277 'test #render() specific layout "view engine"': function(){278 var app = create();279 app.set('view engine', 'jade');280 281 app.get('/', function(req, res){282 res.render('index', { layout: 'cool-layout' });283 });284 285 assert.response(app,286 { url: '/' },287 { body: '<cool><p>Welcome</p></cool>' });288 },289 Added test for periods in dirname when using "view engine"Tj Holowaychukbefore adoption16badda
lines 290–302why, one step back290 'test #render() "view engine" with periods in dirname': function(){291 var app = create();292 app.set('view engine', 'jade');293 294 app.get('/', function(req, res){295 res.render('index', { layout: __dirname + '/fixtures/user/../cool-layout' });296 });297 298 assert.response(app,299 { url: '/' },300 { body: '<cool><p>Welcome</p></cool>' });301 },302 Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 303–321why, one step back303 'test #render() view helpers': function(beforeExit){304 var app = create()305 , calls = 0;306307 app.locals({308 lastName: 'holowaychuk'309 });310311 app.helpers({ 312 greetings: function(sess, lastName){313 return 'Hello ' + sess.name + ' ' + lastName; 314 }315 });316317 var ret = app.dynamicHelpers({318 session: function(req, res){319 ++calls;320 req.should.be.a('object');321 res.should.be.a('object');Merge branch 'features/https'Tj Holowaychukbefore adoption8261437
line 322why, one step back322 this.should.equal(app);Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 323–363why, one step back323 return req.session;324 }325 });326327 assert.equal(app, ret, 'Server#helpers() is not chainable');328 329 app.get('/', function(req, res){330 req.session = { name: 'tj' };331 res.render('dynamic-helpers.jade', { layout: false });332 });333334 app.get('/ejs', function(req, res){335 req.session = { name: 'tj' };336 res.render('dynamic-helpers.ejs', { layout: false });337 });338339 app.get('/precedence', function(req, res){340 req.session = { name: 'tj' };341 res.render('dynamic-helpers.jade', {342 lastName: 'foobar'343 });344 });345 346 assert.response(app,347 { url: '/' },348 { body: '<p>Hello tj holowaychuk</p>' });349 assert.response(app,350 { url: '/ejs' },351 { body: '<p>Hello tj holowaychuk</p>' });352 assert.response(app,353 { url: '/precedence' },354 { body: '<html><body><p>Hello tj foobar</p></body></html>' });355356 beforeExit(function(){357 assert.equal(3, calls);358 });359 },360 361 'test #partial()': function(){362 var app = create();363Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
lines 364–365why, one step back364 app.set('view engine', 'jade');365Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 366–406why, one step back366 // Auto-assigned local w/ collection option367 app.get('/', function(req, res){368 res.render('items.jade', { items: ['one', 'two'] });369 });370 371 assert.response(app,372 { url: '/' },373 { body: '<html><body><ul><li>one</li><li>two</li></ul></body></html>' });374375 // Auto-assigned local w/ collection array 376 var movies = [377 { title: 'Nightmare Before Christmas', director: 'Tim Burton' },378 { title: 'Avatar', director: 'James Cameron' }379 ];380 app.get('/movies', function(req, res){381 res.render('movies.jade', { movies: movies });382 });383 384 var html = [385 '<html>',386 '<body>',387 '<ul>',388 '<li>',389 '<div class="title">Nightmare Before Christmas</div>',390 '<div class="director">Tim Burton</div>',391 '</li>',392 '<li>',393 '<div class="title">Avatar</div>',394 '<div class="director">James Cameron</div>',395 '</li>',396 '</ul>',397 '</body>',398 '</html>'399 ].join('');400401 assert.response(app,402 { url: '/movies' },403 { body: html });404405 // as: str collection option406 app.get('/user', function(req, res){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 407why, one step back407 res.partial('user', {Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 408–409why, one step back408 as: 'person',409 collection: [{ name: 'tj' }]Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 410why, one step back410 });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 411–418why, one step back411 });412 413 assert.response(app,414 { url: '/user' },415 { body: '<p>tj</p>' });416417 // as: with object collection418 app.get('/user/object', function(req, res){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 419why, one step back419 res.partial('user.jade', {Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 420–421why, one step back420 as: 'person',421 collection: { 0: { name: 'tj' }, length: 1 }Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 422why, one step back422 });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 423–430why, one step back423 });424 425 assert.response(app,426 { url: '/user' },427 { body: '<p>tj</p>' });428 429 // as: this collection option430 app.get('/person', function(req, res){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 431why, one step back431 res.partial('person.jade', {Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 432–434why, one step back432 as: this,433 collection: [{ name: 'tj' }],434 locals: { label: 'name:' }Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 435why, one step back435 });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 436–443why, one step back436 });437 438 assert.response(app,439 { url: '/person' },440 { body: '<p>name: tj</p>' });441442 // as: global collection option443 app.get('/videos', function(req, res){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 444why, one step back444 res.partial('video.jade', {Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 445–446why, one step back445 as: global,446 collection: moviesAdded res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 447why, one step back447 });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 448–455why, one step back448 });449450 assert.response(app,451 { url: '/videos' },452 { body: '<p>Tim Burton</p><p>James Cameron</p>' });453 454 // Magic variables455 app.get('/magic', function(req, res){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 456why, one step back456 res.partial('magic.jade', {Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 457–458why, one step back457 as: 'word',458 collection: ['one', 'two', 'three']Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 459why, one step back459 });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 460–467why, one step back460 });461 462 assert.response(app,463 { url: '/magic' },464 { body: '<li class="first">one</li><li class="word-1">two</li><li class="last">three</li>' });465 466 // Non-collection support467 app.get('/movie', function(req, res){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 468why, one step back468 res.partial('movie.jade', {Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
line 469why, one step back469 object: movies[0]Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 470why, one step back470 });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 471–477why, one step back471 });472 473 assert.response(app,474 { url: '/movie' },475 { body: '<li><div class="title">Nightmare Before Christmas</div><div class="director">Tim Burton</div></li>' });476 477 app.get('/video-global', function(req, res){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 478why, one step back478 res.partial('video.jade', {Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 479–480why, one step back479 object: movies[0],480 as: globalAdded res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 481why, one step back481 }); Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 482–489why, one step back482 });483 484 // Non-collection as: global485 assert.response(app,486 { url: '/video-global' },487 { body: '<p>Tim Burton</p>' });488489 app.get('/person-this', function(req, res){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 490why, one step back490 res.partial('person.jade', {Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 491–493why, one step back491 object: { name: 'tj' },492 locals: { label: 'User:' },493 as: thisAdded res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 494why, one step back494 }); Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 495–499why, one step back495 });496 497 // Non-collection as: this498 assert.response(app,499 { url: '/person-this' },Removed partial() / render() status and header optionsTj Holowaychukbefore adoptionaaa8415
line 500why, one step back500 { body: '<p>User: tj</p>' });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 501–503why, one step back501502 // No options503 app.get('/nothing', function(req, res){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 504why, one step back504 res.partial('hello.ejs');Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 505–512why, one step back505 });506 507 assert.response(app,508 { url: '/nothing' },509 { body: 'Hello' });510511 // Path segments + "as"512 app.get('/role/as', function(req, res){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 513why, one step back513 res.partial('user/role.ejs', { as: 'role', collection: ['admin', 'member'] });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 514–521why, one step back514 });515516 assert.response(app,517 { url: '/role/as' },518 { body: '<li>Role: admin</li><li>Role: member</li>' });519520 // Deduce name from last segment521 app.get('/role', function(req, res){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 522why, one step back522 res.partial('user/role.ejs', ['admin', 'member']);Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 523–529why, one step back523 });524525 assert.response(app,526 { url: '/role' },527 { body: '<li>Role: admin</li><li>Role: member</li>' });528 },529 Added test for partial locals on subsequent callsTj Holowaychukbefore adoption1130a23
lines 530–541why, one step back530 'test #partial() with several calls': function(){531 var app = create();532533 app.get('/', function(req, res, next){534 res.render('list.jade', { layout: false });535 });536 537 assert.response(app,538 { url: '/' },539 { body: '<ul><li>foo</li><li>empty</li></ul>' });540 },541 Added another partial locals testTj Holowaychukbefore adoptionab4c911
lines 542–553why, one step back542 'test #partial() with several calls using locals': function(){543 var app = create();544545 app.get('/', function(req, res, next){546 res.render('list2.jade', { layout: false });547 });548 549 assert.response(app,550 { url: '/' },551 { body: '<ul><li>foo</li><li>bar</li><li>empty</li></ul>' });552 },553 Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 554–556why, one step back554 'test #partial() locals': function(){555 var app = create();556Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
lines 557–558why, one step back557 app.set('view engine', 'jade');558Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
line 559why, one step back559 app.get('/', function(req, res, next){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 560why, one step back560 res.partial('pet-count', {Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 561–565why, one step back561 locals: {562 pets: {563 length: 5564 }565 }Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 566why, one step back566 });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 567–579why, one step back567 });568569 assert.response(app,570 { url: '/' },571 { body: 'We have 5 cool pets\n' });572 },573 574 'test #partial() locals precedence': function(){575 var app = create();576577 app.get('/', function(req, res, next){578 res.render('greetings.jade', {579 name: 'TJ'Added res.render() .locals support back to aid in migration processTj Holowaychukbefore adoption07d06ad
line 580why, one step back580 , locals: { otherName: 'Overridden' }Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 581–587why, one step back581 });582 });583584 assert.response(app,585 { url: '/' },586 { body: '<html><body><h1>TJ</h1><p>Welcome Overridden</p></body></html>' });587 },Added partial() index testTj Holowaychukbefore adoptiond70fee7
lines 588–602why, one step back588589 'test #partial() index': function(){590 var app = create();591592 app.set('view engine', 'jade');593594 app.get('/ferret', function(req, res){595 res.partial('ferret', { name: 'Tobi' });596 });597598 assert.response(app,599 { url: '/ferret' },600 { body: '<li class="ferret">Tobi</li>' });601 },602Added failing test for partial("foo") loading the indexTj Holowaychukbefore adoption92967d3
lines 603–618why, one step back603 'test #partial() relative index': function(){604 var app = create();605606 app.set('view engine', 'jade');607608 app.get('/ferret', function(req, res){609 var tobi = { name: 'Tobi' }610 , loki = { name: 'Loki' };611 res.partial('ferret/list', { object: [tobi, loki] });612 });613614 assert.response(app,615 { url: '/ferret' },616 { body: '<ul id="ferrets"><li class="ferret">Tobi</li><li class="ferret">Loki</li></ul>' });617 },618Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 619–622why, one step back619 'test #partial() object': function(){620 var app = create();621622 app.get('/', function(req, res, next){Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 623why, one step back623 res.partial('movie.jade', {Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 624–625why, one step back624 title: 'Foobar'625 , director: 'Tim Burton'Added res.partial(), using the same interface as partial() within a view. Closes #539Tj Holowaychukbefore adoptiondd9406c
line 626why, one step back626 });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 627–770why, one step back627 });628629 assert.response(app,630 { url: '/' },631 { body: '<li><div class="title">Foobar</div><div class="director">Tim Burton</div></li>' });632 },633 634 'test #partial() locals with collection': function(){635 var app = create();636637 app.get('/', function(req, res, next){638 res.render('pet-land.jade', {639 pets: ['Ewald']640 });641 });642643 assert.response(app,644 { url: '/' },645 { body: '<html><body><div><li>Ewald is the coolest of Animal land</li></div></body></html>' });646 },647 648 'test #partial() inheriting initial locals': function(){649 var app = create();650651 app.get('/pets', function(req, res, next){652 res.render('pets.jade', {653 site: 'My Cool Pets'654 , pets: ['Tobi', 'Jane', 'Bandit']655 });656 });657658 var html = [659 '<html>',660 '<body>',661 '<h1>My Cool Pets</h1>',662 '<p>We have 3 cool pets\n</p>',663 '<ul>',664 '<li>Tobi is the coolest of My Cool Pets</li>',665 '<li>Jane</li>',666 '<li>Bandit</li>',667 '</ul>',668 '</body>',669 '</html>'670 ].join('');671672 assert.response(app,673 { url: '/pets' },674 { body: html });675 },676 677 'test #partial() with array-like collection': function(){678 var app = create();679680 var movies = {681 0: { title: 'Nightmare Before Christmas', director: 'Tim Burton' },682 1: { title: 'Avatar', director: 'James Cameron' },683 length: 2684 };685 app.get('/movies', function(req, res){686 res.render('movies.jade', { movies: movies });687 });688 689 var html = [690 '<html>',691 '<body>',692 '<ul>',693 '<li>',694 '<div class="title">Nightmare Before Christmas</div>',695 '<div class="director">Tim Burton</div>',696 '</li>',697 '<li>',698 '<div class="title">Avatar</div>',699 '<div class="director">James Cameron</div>',700 '</li>',701 '</ul>',702 '</body>',703 '</html>'704 ].join('');705706 assert.response(app,707 { url: '/movies' },708 { body: html });709 },710 711 'test "partials" setting': function(){712 var app = create();713 app.set('partials', __dirname + '/fixtures/sub-templates');714715 app.get('/', function(req, res){716 res.render('items.jade', {717 layout: false,718 items: ['foo', 'bar']719 });720 });721 722 assert.response(app,723 { url: '/' },724 { body: '<ul><li>foo</li><li>bar</li></ul>' });725 },726 727 'test "view options"': function(){728 var app = create();729 730 app.set('view options', {731 layout: false732 , open: '{{'733 , close: '}}'734 });735 736 app.get('/', function(req, res, next){737 res.render('user.ejs', {738 name: 'tj'739 , email: 'tj@vision-media.ca'740 });741 });742 743 app.get('/video', function(req, res, next){744 res.render('video.ejs', {745 open: '<?'746 , close: '?>'747 , title: 'keyboard cat'748 });749 });750 751 assert.response(app,752 { url: '/' },753 { body: '<h1>tj</h1>\n<p>tj@vision-media.ca</p>' });754 assert.response(app,755 { url: '/video' },756 { body: '<h1>keyboard cat</h1>' });757 },758 759 'test .register()': function(){760 var app = create();761 762 app.register('.bar', require('jade'));763 764 app.get('/', function(req, res, next){765 res.render('foo.bar', { layout: false });766 });767 768 assert.response(app,769 { url: '/' },770 { body: '<p>This is actually jade :)</p>' });made`str` localmgutzbefore adoptioneae1670
line 771why, one step back771 },Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f
lines 772–773why, one step back772 773 'test res.local()': function(){made`str` localmgutzbefore adoptioneae1670
lines 774–775why, one step back774 var app = create();775 Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f
lines 776–780why, one step back776 app.get('/video', function(req, res, next){777 res.local('open', '<?');778 res.local('close', '?>');779 res.local('title', 'Wahoo');780 res.render('video.ejs', { layout: false });made`str` localmgutzbefore adoptioneae1670
line 781why, one step back781 });Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f
lines 782–808why, one step back782 783 assert.response(app,784 { url: '/video' },785 { body: '<h1>Wahoo</h1>' });786 },787 788 'test res.local() render() precedence': function(){789 var app = create();790 791 app.get('/video', function(req, res, next){792 res.local('open', '<?');793 res.local('close', '?>');794 res.local('title', 'Wahoo');795 res.render('video.ejs', { layout: false, title: 'keyboard cat' });796 });797 798 assert.response(app,799 { url: '/video' },800 { body: '<h1>keyboard cat</h1>' });801 },802 803 'test res.local() "view options" precedence': function(){804 var app = create();805 806 app.set('view options', {807 layout: false808 , open: '<?'added more local testsTj Holowaychukbefore adoptiondc6d469
line 809why, one step back809 , title: 'Original'Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f
line 810why, one step back810 });added more local testsTj Holowaychukbefore adoptiondc6d469
lines 811–812why, one step back811812 function setTitle(req, res, next) {Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f
line 813why, one step back813 res.local('title', 'Wahoo');added more local testsTj Holowaychukbefore adoptiondc6d469
lines 814–817why, one step back814 next();815 }816817 app.get('/video', setTitle, function(req, res, next){semi-colonsTj Holowaychukbefore adoption0800141
line 818why, one step back818 res.local('close', '?>');Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f
lines 819–821why, one step back819 res.render('video.ejs', { layout: false, title: 'keyboard cat' });820 });821 added more local testsTj Holowaychukbefore adoptiondc6d469
line 822why, one step back822 app.get('/video/2', setTitle, function(req, res, next){semi-colonsTj Holowaychukbefore adoption0800141
line 823why, one step back823 res.local('close', '?>');added more local testsTj Holowaychukbefore adoptiondc6d469
lines 824–827why, one step back824 res.render('video.ejs', { layout: false });825 });826827 app.get('/video/3', function(req, res, next){semi-colonsTj Holowaychukbefore adoption0800141
line 828why, one step back828 res.local('close', '?>');added more local testsTj Holowaychukbefore adoptiondc6d469
lines 829–831why, one step back829 res.render('video.ejs', { layout: false });830 });831Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f
lines 832–834why, one step back832 assert.response(app,833 { url: '/video' },834 { body: '<h1>keyboard cat</h1>' });added more local testsTj Holowaychukbefore adoptiondc6d469
lines 835–842why, one step back835836 assert.response(app,837 { url: '/video/2' },838 { body: '<h1>Wahoo</h1>' });839840 assert.response(app,841 { url: '/video/3' },842 { body: '<h1>Original</h1>' });Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f
lines 843–863why, one step back843 },844 845 'test res.local() partials': function(){846 var app = create();847 848 app.set('view options', {849 site: 'My Cool Pets'850 });851 852 app.get('/pets', function(req, res, next){853 res.local('pets', ['Tobi']);854 next();855 });856 857 app.get('/pets', function(req, res, next){858 var pets;859 if (pets = res.local('pets')) {860 pets.push('Jane', 'Bandit');861 }862 next();863 });made`str` localmgutzbefore adoptioneae1670
line 864why, one step back864Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f
lines 865–882why, one step back865 app.get('/pets', function(req, res, next){866 res.render('pets.jade');867 });868869 var html = [870 '<html>',871 '<body>',872 '<h1>My Cool Pets</h1>',873 '<p>We have 3 cool pets\n</p>',874 '<ul>',875 '<li>Tobi is the coolest of My Cool Pets</li>',876 '<li>Jane</li>',877 '<li>Bandit</li>',878 '</ul>',879 '</body>',880 '</html>'881 ].join('');882made`str` localmgutzbefore adoptioneae1670
line 883why, one step back883 assert.response(app,Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f
lines 884–885why, one step back884 { url: '/pets' },885 { body: html });Fixed express(1) modeTj Holowaychukbefore adoptionc24a6b2
lines 886–887why, one step back886 }887};