Skip to content
Myr

view.test.js

This file

Path

test/view.test.js

903 lines · 23.1 KiB · JavaScript

Last changed by

Merge branch 'features/https'Tj Holowaychukbefore adoption8261437

History of this file

Take it

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

master is 2.0.0-preTj Holowaychukbefore adoptionce2a18f

lines 1–5why, one step back
1
2/**3 * Module dependencies.4 */5

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 6–9why, one step back
6var 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 back
10 , View = require('../lib/view')

Utilizing the new View / Partial constructorsTj Holowaychukbefore adoptionad32441

line 11why, one step back
11 , Partial = View.Partial

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 12–16why, one step back
12
13/**14 * Create a test server with views set to ./fixtures.15 */16

master is 2.0.0-preTj Holowaychukbefore adoptionce2a18f

line 17why, one step back
17var create = function(){

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 18–20why, one step back
18 var app = express.createServer.apply(express, arguments);
19 app.set('views', __dirname + '/fixtures');20 return app;

master is 2.0.0-preTj Holowaychukbefore adoptionce2a18f

line 21why, one step back
21};

using should / refactored testsTj Holowaychukbefore adoption643879f

line 22why, one step back
22

master is 2.0.0-preTj Holowaychukbefore adoptionce2a18f

line 23why, one step back
23module.exports = {

Started View implementationTj Holowaychukbefore adoption9f4b736

lines 24–56why, one step back
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');56

Utilizing the new View / Partial constructorsTj Holowaychukbefore adoptionad32441

line 57why, one step back
57 var view = new View('/user', { defaultEngine: 'jade' });

Started View implementationTj Holowaychukbefore adoption9f4b736

lines 58–70why, one step back
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');70

Utilizing the new View / Partial constructorsTj Holowaychukbefore adoptionad32441

line 71why, one step back
71 var view = new View('/user', { defaultEngine: 'jade' });

Started View implementationTj Holowaychukbefore adoption9f4b736

lines 72–85why, one step back
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

Utilizing the new View / Partial constructorsTj Holowaychukbefore adoptionad32441

lines 86–95why, one step back
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

Merge branch 'views'Tj Holowaychukbefore adoption0ed121d

lines 96–102why, one step back
96 'test Partial.resolveObjectName()': function(){
97 var resolve = Partial.resolveObjectName;98 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');

Started View implementationTj Holowaychukbefore adoption9f4b736

lines 103–104why, one step back
103 },
104

Utilizing the new View / Partial constructorsTj Holowaychukbefore adoptionad32441

line 105why, one step back
105 'test Partial#path for partials': function(){

Merge branch 'partial-lookup'Tj Holowaychukbefore adoption647bb41

lines 106–108why, one step back
106 var fixtures = __dirname + '/fixtures';
107 108 var view = new Partial('user.jade', { root: fixtures });

Merge branch 'partials'Tj Holowaychukbefore adoptiondfbbd4f

line 109why, one step back
109 view.path.should.equal(fixtures + '/user.jade');

Utilizing the new View / Partial constructorsTj Holowaychukbefore adoptionad32441

line 110why, one step back
110

Merge branch 'partial-lookup'Tj Holowaychukbefore adoption647bb41

line 111why, one step back
111 var view = new Partial('user', { parentView: view, root: fixtures });

Merge branch 'partials'Tj Holowaychukbefore adoptiondfbbd4f

line 112why, one step back
112 view.path.should.equal(fixtures + '/user.jade');

Utilizing the new View / Partial constructorsTj Holowaychukbefore adoptionad32441

lines 113–114why, one step back
113
114 var view = new Partial('forum/thread', { parentView: view });

Merge branch 'partials'Tj Holowaychukbefore adoptiondfbbd4f

line 115why, one step back
115 view.path.should.equal(fixtures + '/forum/thread.jade');

Utilizing the new View / Partial constructorsTj Holowaychukbefore adoptionad32441

line 116why, one step back
116

Merge branch 'partial-lookup'Tj Holowaychukbefore adoption647bb41

line 117why, one step back
117 var view = new Partial('forum/thread.jade', { root: fixtures });

Merge branch 'partials'Tj Holowaychukbefore adoptiondfbbd4f

line 118why, one step back
118 view.path.should.equal(fixtures + '/forum/thread.jade');

Merge branch 'partial-lookup'Tj Holowaychukbefore adoption647bb41

lines 119–120why, one step back
119
120 var view = new Partial('thread', { parentView: view });

Merge branch 'partials'Tj Holowaychukbefore adoptiondfbbd4f

line 121why, one step back
121 view.path.should.equal(fixtures + '/forum/thread.jade');

Started View implementationTj Holowaychukbefore adoption9f4b736

lines 122–123why, one step back
122 },
123

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 124–135why, one step back
124 'test #render()': function(){
125 var app = create();126 app.set('view engine', 'jade');127128 app.get('/', function(req, res){129 res.render('index.jade', { layout: false });130 });131132 app.get('/jade', function(req, res){133 res.render('index', { layout: false });134 });135

Utilizing the new View / Partial constructorsTj Holowaychukbefore adoptionad32441

lines 136–138why, one step back
136 // app.get('/haml', function(req, res){
137 // res.render('hello.haml', { layout: false });138 // });

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 139–153why, one step back
139
140 app.get('/callback/layout/no-options', function(req, res){141 res.render('hello.jade', function(err, str){142 assert.ok(!err);143 res.send(str.replace(':(', ':)'));144 });145 });146147 app.get('/callback/layout', function(req, res){148 res.render('hello.jade', {}, function(err, str){149 assert.ok(!err);150 res.send(str.replace(':(', ':)'));151 });152 });153

Utilizing the new View / Partial constructorsTj Holowaychukbefore adoptionad32441

lines 154–159why, one step back
154 // app.get('/callback', function(req, res){
155 // res.render('hello.haml', { layout: false }, function(err, str){156 // assert.ok(!err);157 // res.send(str.replace('Hello World', ':)'));158 // });159 // });

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 160–171why, one step back
160
161 app.get('/invalid', function(req, res){162 res.render('invalid.jade', { layout: false });163 });164165 app.get('/invalid-async', function(req, res){166 process.nextTick(function(){167 res.render('invalid.jade', { layout: false });168 });169 });170171 app.get('/error', function(req, res){

indentation fixTj Holowaychukbefore adoption4a1edc0

lines 172–174why, one step back
172 res.render('invalid.jade', { layout: false }, function(err){
173 res.send(err.arguments[0]);174 });

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 175–182why, one step back
175 });
176177 app.get('/absolute', function(req, res){178 res.render(__dirname + '/fixtures/index.jade', { layout: false });179 });180181 assert.response(app,182 { url: '/' },

Changed; charsets are no longer impliedTj Holowaychukbefore adoption9fc3499

line 183why, one step back
183 { body: '<p>Welcome</p>', headers: { 'Content-Type': 'text/html' }});

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 184–189why, one step back
184 assert.response(app,
185 { url: '/jade' },186 { body: '<p>Welcome</p>' });187 assert.response(app,188 { url: '/absolute' },189 { body: '<p>Welcome</p>' });

Utilizing the new View / Partial constructorsTj Holowaychukbefore adoptionad32441

lines 190–195why, one step back
190 // assert.response(app,
191 // { url: '/haml' },192 // { body: '\n<p>Hello World</p>' });193 // assert.response(app,194 // { url: '/callback' },195 // { body: '\n<p>:)</p>' });

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 196–272why, one step back
196 assert.response(app,
197 { url: '/callback/layout' },198 { body: '<html><body><p>:)</p></body></html>' });199 assert.response(app,200 { url: '/callback/layout/no-options' },201 { body: '<html><body><p>:)</p></body></html>' });202 assert.response(app,203 { url: '/error' },204 { body: 'doesNotExist' });205 assert.response(app,206 { url: '/invalid' },207 function(res){208 assert.ok(res.body.indexOf('ReferenceError') >= 0);209 assert.ok(res.body.indexOf('doesNotExist') >= 0);210 });211 assert.response(app,212 { url: '/invalid-async' },213 function(res){214 assert.ok(res.body.indexOf('ReferenceError') >= 0);215 assert.ok(res.body.indexOf('doesNotExist') >= 0);216 });217 },218 219 'test #render() layout': function(){220 var app = create();221 app.set('view engine', 'jade');222223 app.get('/', function(req, res){224 res.render('index.jade');225 });226 app.get('/jade', function(req, res){227 res.render('index');228 });229230 assert.response(app,231 { url: '/' },232 { body: '<html><body><p>Welcome</p></body></html>' });233 },234 235 'test #render() specific layout': function(beforeExit){236 var app = create()237 , called;238239 app.get('/', function(req, res){240 res.render('index.jade', { layout: 'cool-layout.jade' }, function(err, html){241 called = true;242 res.send(html);243 });244 });245 app.get('/no-ext', function(req, res){246 res.render('index.jade', { layout: 'cool-layout' });247 });248 app.get('/relative', function(req, res){249 res.render('index.jade', { layout: 'layouts/foo.jade' });250 });251 app.get('/absolute', function(req, res){252 res.render('index.jade', { layout: __dirname + '/fixtures/layouts/foo.jade' });253 });254 app.get('/nope', function(req, res){255 res.render('index.jade', { layout: 'nope.jade' });256 });257258 assert.response(app,259 { url: '/' },260 { body: '<cool><p>Welcome</p></cool>' });261 assert.response(app,262 { url: '/no-ext' },263 { body: '<cool><p>Welcome</p></cool>' });264 assert.response(app,265 { url: '/relative' },266 { body: '<foo></foo>' });267 assert.response(app,268 { url: '/absolute' },269 { body: '<foo></foo>' });270 assert.response(app,271 { url: '/nope' },272 function(res){

Added qs submodTj Holowaychukbefore adoption05c2946

lines 273–274why, one step back
273 assert.ok(~res.body.indexOf('Error: E'));
274 assert.ok(~res.body.indexOf('nope/index.jade'));

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 275–294why, one step back
275 });
276277 beforeExit(function(){278 assert.ok(called, 'Layout callback never called'); 279 });280 },281 282 'test #render() specific layout "view engine"': function(){283 var app = create();284 app.set('view engine', 'jade');285 286 app.get('/', function(req, res){287 res.render('index', { layout: 'cool-layout' });288 });289 290 assert.response(app,291 { url: '/' },292 { body: '<cool><p>Welcome</p></cool>' });293 },294

Added test for periods in dirname when using "view engine"Tj Holowaychukbefore adoption16badda

lines 295–307why, one step back
295 'test #render() "view engine" with periods in dirname': function(){
296 var app = create();297 app.set('view engine', 'jade');298 299 app.get('/', function(req, res){300 res.render('index', { layout: __dirname + '/fixtures/user/../cool-layout' });301 });302 303 assert.response(app,304 { url: '/' },305 { body: '<cool><p>Welcome</p></cool>' });306 },307

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 308–370why, one step back
308 'test #render() scope': function(){
309 var app = create();310 app.set('view engine', 'jade');311 312 app.get('/', function(req, res){313 req.internal = '1';314 req.method = function(){315 return this.internal;316 };317 res.render('scope.jade', { layout: false });318 });319 320 app.get('/custom', function(req, res){321 var scope = {322 internal: '2',323 method: function(){324 return this.internal;325 }326 };327 res.render('scope.jade', { layout: false, scope: scope });328 });329 330 assert.response(app,331 { url: '/' },332 { body: '<p>1</p>'});333334 assert.response(app,335 { url: '/custom' },336 { body: '<p>2</p>'});337 },338 339 'test #render() status': function(){340 var app = create();341 342 app.get('/', function(req, res){343 res.render('hello.jade', {344 layout: false,345 status: 404346 });347 });348 349 assert.response(app,350 { url: '/' },351 { body: '<p>:(</p>', status: 404 });352 },353 354 'test #render() headers': function(){355 var app = create();356 357 app.get('/', function(req, res){358 res.render('hello.jade', {359 layout: false,360 status: 500,361 headers: {362 'X-Foo': 'bar'363 }364 });365 });366 367 assert.response(app,368 { url: '/' },369 { body: '<p>:(</p>', status: 500, headers: {370 'X-Foo': 'bar',

Changed; charsets are no longer impliedTj Holowaychukbefore adoption9fc3499

line 371why, one step back
371 'Content-Type': 'text/html'

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 372–378why, one step back
372 }});
373 },374 375 'test #render() view helpers': function(beforeExit){376 var app = create()377 , calls = 0;378

Aliased app.helpers() as app.locals(). Closes #481Tj Holowaychukbefore adoption19965fa

lines 379–382why, one step back
379 app.locals({
380 lastName: 'holowaychuk'381 });382

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 383–391why, one step back
383 app.helpers({
384 greetings: function(sess, lastName){385 return 'Hello ' + sess.name + ' ' + lastName; 386 }387 });388389 var ret = app.dynamicHelpers({390 session: function(req, res){391 ++calls;

shouldTj Holowaychukbefore adoption6bb42ff

lines 392–393why, one step back
392 req.should.be.a('object');
393 res.should.be.a('object');

Merge branch 'features/https'Tj Holowaychukbefore adoption8261437

line 394why, one step back
394 this.should.equal(app);

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 395–413why, one step back
395 return req.session;
396 }397 });398399 assert.equal(app, ret, 'Server#helpers() is not chainable');400 401 app.get('/', function(req, res){402 req.session = { name: 'tj' };403 res.render('dynamic-helpers.jade', { layout: false });404 });405406 app.get('/ejs', function(req, res){407 req.session = { name: 'tj' };408 res.render('dynamic-helpers.ejs', { layout: false });409 });410411 app.get('/precedence', function(req, res){412 req.session = { name: 'tj' };413 res.render('dynamic-helpers.jade', {

removed locals: from view testsTj Holowaychukbefore adoption3ad6ab8

line 414why, one step back
414 lastName: 'foobar'

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 415–437why, one step back
415 });
416 });417 418 assert.response(app,419 { url: '/' },420 { body: '<p>Hello tj holowaychuk</p>' });421 assert.response(app,422 { url: '/ejs' },423 { body: '<p>Hello tj holowaychuk</p>' });424 assert.response(app,425 { url: '/precedence' },426 { body: '<html><body><p>Hello tj foobar</p></body></html>' });427428 beforeExit(function(){429 assert.equal(3, calls);430 });431 },432 433 'test #partial()': function(){434 var app = create();435436 // Auto-assigned local w/ collection option437 app.get('/', function(req, res){

removed locals: from view testsTj Holowaychukbefore adoption3ad6ab8

line 438why, one step back
438 res.render('items.jade', { items: ['one', 'two'] });

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 439–450why, one step back
439 });
440 441 assert.response(app,442 { url: '/' },443 { body: '<html><body><ul><li>one</li><li>two</li></ul></body></html>' });444445 // Auto-assigned local w/ collection array 446 var movies = [447 { title: 'Nightmare Before Christmas', director: 'Tim Burton' },448 { title: 'Avatar', director: 'James Cameron' }449 ];450 app.get('/movies', function(req, res){

removed locals: from view testsTj Holowaychukbefore adoption3ad6ab8

line 451why, one step back
451 res.render('movies.jade', { movies: movies });

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 452–599why, one step back
452 });
453 454 var html = [455 '<html>',456 '<body>',457 '<ul>',458 '<li>',459 '<div class="title">Nightmare Before Christmas</div>',460 '<div class="director">Tim Burton</div>',461 '</li>',462 '<li>',463 '<div class="title">Avatar</div>',464 '<div class="director">James Cameron</div>',465 '</li>',466 '</ul>',467 '</body>',468 '</html>'469 ].join('');470471 assert.response(app,472 { url: '/movies' },473 { body: html });474475 // as: str collection option476 app.get('/user', function(req, res){477 res.send(res.partial('user.jade', {478 as: 'person',479 collection: [{ name: 'tj' }]480 }));481 });482 483 assert.response(app,484 { url: '/user' },485 { body: '<p>tj</p>' });486487 // as: with object collection488 app.get('/user/object', function(req, res){489 res.send(res.partial('user.jade', {490 as: 'person',491 collection: { 0: { name: 'tj' }, length: 1 }492 }));493 });494 495 assert.response(app,496 { url: '/user' },497 { body: '<p>tj</p>' });498 499 // as: this collection option500 app.get('/person', function(req, res){501 res.send(res.partial('person.jade', {502 as: this,503 collection: [{ name: 'tj' }],504 locals: { label: 'name:' }505 }));506 });507 508 assert.response(app,509 { url: '/person' },510 { body: '<p>name: tj</p>' });511512 // as: global collection option513 app.get('/videos', function(req, res){514 res.send(res.partial('video.jade', {515 as: global,516 collection: movies517 }));518 });519520 assert.response(app,521 { url: '/videos' },522 { body: '<p>Tim Burton</p><p>James Cameron</p>' });523 524 // Magic variables525 app.get('/magic', function(req, res){526 res.send(res.partial('magic.jade', {527 as: 'word',528 collection: ['one', 'two', 'three']529 }));530 });531 532 assert.response(app,533 { url: '/magic' },534 { body: '<li class="first">one</li><li class="word-1">two</li><li class="last">three</li>' });535 536 // Non-collection support537 app.get('/movie', function(req, res){538 res.send(res.partial('movie.jade', {539 object: movies[0]540 }));541 });542 543 assert.response(app,544 { url: '/movie' },545 { body: '<li><div class="title">Nightmare Before Christmas</div><div class="director">Tim Burton</div></li>' });546 547 app.get('/video-global', function(req, res){548 res.send(res.partial('video.jade', {549 object: movies[0],550 as: global551 })); 552 });553 554 // Non-collection as: global555 assert.response(app,556 { url: '/video-global' },557 { body: '<p>Tim Burton</p>' });558559 app.get('/person-this', function(req, res){560 res.send(res.partial('person.jade', {561 object: { name: 'tj' },562 locals: { label: 'User:' },563 as: this564 })); 565 });566 567 // Non-collection as: this568 assert.response(app,569 { url: '/person-this' },570 { body: '<p>User: tj</p>' });571572 // No options573 app.get('/nothing', function(req, res){574 res.send(res.partial('hello.ejs'));575 });576 577 assert.response(app,578 { url: '/nothing' },579 { body: 'Hello' });580581 // Path segments + "as"582 app.get('/role/as', function(req, res){583 res.send(res.partial('user/role.ejs', { as: 'role', collection: ['admin', 'member'] }));584 });585586 assert.response(app,587 { url: '/role/as' },588 { body: '<li>Role: admin</li><li>Role: member</li>' });589590 // Deduce name from last segment591 app.get('/role', function(req, res){592 res.send(res.partial('user/role.ejs', ['admin', 'member']));593 });594595 assert.response(app,596 { url: '/role' },597 { body: '<li>Role: admin</li><li>Role: member</li>' });598 },599

Added test for partial locals on subsequent callsTj Holowaychukbefore adoption1130a23

lines 600–611why, one step back
600 'test #partial() with several calls': function(){
601 var app = create();602603 app.get('/', function(req, res, next){604 res.render('list.jade', { layout: false });605 });606 607 assert.response(app,608 { url: '/' },609 { body: '<ul><li>foo</li><li>empty</li></ul>' });610 },611

Added another partial locals testTj Holowaychukbefore adoptionab4c911

lines 612–623why, one step back
612 'test #partial() with several calls using locals': function(){
613 var app = create();614615 app.get('/', function(req, res, next){616 res.render('list2.jade', { layout: false });617 });618 619 assert.response(app,620 { url: '/' },621 { body: '<ul><li>foo</li><li>bar</li><li>empty</li></ul>' });622 },623

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 624–646why, one step back
624 'test #partial() locals': function(){
625 var app = create();626627 app.get('/', function(req, res, next){628 res.send(res.partial('pet-count.jade', {629 locals: {630 pets: {631 length: 5632 }633 }634 }));635 });636637 assert.response(app,638 { url: '/' },639 { body: 'We have 5 cool pets\n' });640 },641 642 'test #partial() locals precedence': function(){643 var app = create();644645 app.get('/', function(req, res, next){646 res.render('greetings.jade', {

removed locals: from view testsTj Holowaychukbefore adoption3ad6ab8

lines 647–648why, one step back
647 name: 'TJ'
648 , otherName: 'Overridden'

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 649–676why, one step back
649 });
650 });651652 assert.response(app,653 { url: '/' },654 { body: '<html><body><h1>TJ</h1><p>Welcome Overridden</p></body></html>' });655 },656 657 'test #partial() object': function(){658 var app = create();659660 app.get('/', function(req, res, next){661 res.send(res.partial('movie.jade', {662 title: 'Foobar'663 , director: 'Tim Burton'664 }));665 });666667 assert.response(app,668 { url: '/' },669 { body: '<li><div class="title">Foobar</div><div class="director">Tim Burton</div></li>' });670 },671 672 'test #partial() locals with collection': function(){673 var app = create();674675 app.get('/', function(req, res, next){676 res.render('pet-land.jade', {

removed locals: from view testsTj Holowaychukbefore adoption3ad6ab8

line 677why, one step back
677 pets: ['Ewald']

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 678–690why, one step back
678 });
679 });680681 assert.response(app,682 { url: '/' },683 { body: '<html><body><div><li>Ewald is the coolest of Animal land</li></div></body></html>' });684 },685 686 'test #partial() inheriting initial locals': function(){687 var app = create();688689 app.get('/pets', function(req, res, next){690 res.render('pets.jade', {

removed locals: from view testsTj Holowaychukbefore adoption3ad6ab8

lines 691–692why, one step back
691 site: 'My Cool Pets'
692 , pets: ['Tobi', 'Jane', 'Bandit']

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 693–723why, one step back
693 });
694 });695696 var html = [697 '<html>',698 '<body>',699 '<h1>My Cool Pets</h1>',700 '<p>We have 3 cool pets\n</p>',701 '<ul>',702 '<li>Tobi is the coolest of My Cool Pets</li>',703 '<li>Jane</li>',704 '<li>Bandit</li>',705 '</ul>',706 '</body>',707 '</html>'708 ].join('');709710 assert.response(app,711 { url: '/pets' },712 { body: html });713 },714 715 'test #partial() with array-like collection': function(){716 var app = create();717718 var movies = {719 0: { title: 'Nightmare Before Christmas', director: 'Tim Burton' },720 1: { title: 'Avatar', director: 'James Cameron' },721 length: 2722 };723 app.get('/movies', function(req, res){

removed locals: from view testsTj Holowaychukbefore adoption3ad6ab8

line 724why, one step back
724 res.render('movies.jade', { movies: movies });

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 725–755why, one step back
725 });
726 727 var html = [728 '<html>',729 '<body>',730 '<ul>',731 '<li>',732 '<div class="title">Nightmare Before Christmas</div>',733 '<div class="director">Tim Burton</div>',734 '</li>',735 '<li>',736 '<div class="title">Avatar</div>',737 '<div class="director">James Cameron</div>',738 '</li>',739 '</ul>',740 '</body>',741 '</html>'742 ].join('');743744 assert.response(app,745 { url: '/movies' },746 { body: html });747 },748 749 'test "partials" setting': function(){750 var app = create();751 app.set('partials', __dirname + '/fixtures/sub-templates');752753 app.get('/', function(req, res){754 res.render('items.jade', {755 layout: false,

removed locals: from view testsTj Holowaychukbefore adoption3ad6ab8

line 756why, one step back
756 items: ['foo', 'bar']

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 757–761why, one step back
757 });
758 });759 760 assert.response(app,761 { url: '/' },

Utilizing the new View / Partial constructorsTj Holowaychukbefore adoptionad32441

line 762why, one step back
762 { body: '<ul><li>foo</li><li>bar</li></ul>' });

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 763–768why, one step back
763 },
764 765 'test "view options"': function(){766 var app = create();767 768 app.set('view options', {

fixed "view options" supportTj Holowaychukbefore adoption38b3f1b

lines 769–771why, one step back
769 layout: false
770 , open: '{{'771 , close: '}}'

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 772–775why, one step back
772 });
773 774 app.get('/', function(req, res, next){775 res.render('user.ejs', {

removed locals: from view testsTj Holowaychukbefore adoption3ad6ab8

lines 776–777why, one step back
776 name: 'tj'
777 , email: 'tj@vision-media.ca'

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 778–782why, one step back
778 });
779 });780 781 app.get('/video', function(req, res, next){782 res.render('video.ejs', {

removed locals: from view testsTj Holowaychukbefore adoption3ad6ab8

lines 783–785why, one step back
783 open: '<?'
784 , close: '?>'785 , title: 'keyboard cat'

using should / refactored testsTj Holowaychukbefore adoption643879f

lines 786–808why, one step back
786 });
787 });788 789 assert.response(app,790 { url: '/' },791 { body: '<h1>tj</h1>\n<p>tj@vision-media.ca</p>' });792 assert.response(app,793 { url: '/video' },794 { body: '<h1>keyboard cat</h1>' });795 },796 797 'test .register()': function(){798 var app = create();799 800 app.register('.bar', require('jade'));801 802 app.get('/', function(req, res, next){803 res.render('foo.bar', { layout: false });804 });805 806 assert.response(app,807 { url: '/' },808 { body: '<p>This is actually jade :)</p>' });

made`str` localmgutzbefore adoptioneae1670

line 809why, one step back
809 },

Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f

lines 810–811why, one step back
810
811 'test res.local()': function(){

made`str` localmgutzbefore adoptioneae1670

lines 812–813why, one step back
812 var app = create();
813

Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f

lines 814–818why, one step back
814 app.get('/video', function(req, res, next){
815 res.local('open', '<?');816 res.local('close', '?>');817 res.local('title', 'Wahoo');818 res.render('video.ejs', { layout: false });

made`str` localmgutzbefore adoptioneae1670

line 819why, one step back
819 });

Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f

lines 820–879why, one step back
820
821 assert.response(app,822 { url: '/video' },823 { body: '<h1>Wahoo</h1>' });824 },825 826 'test res.local() render() precedence': function(){827 var app = create();828 829 app.get('/video', function(req, res, next){830 res.local('open', '<?');831 res.local('close', '?>');832 res.local('title', 'Wahoo');833 res.render('video.ejs', { layout: false, title: 'keyboard cat' });834 });835 836 assert.response(app,837 { url: '/video' },838 { body: '<h1>keyboard cat</h1>' });839 },840 841 'test res.local() "view options" precedence': function(){842 var app = create();843 844 app.set('view options', {845 layout: false846 , open: '<?'847 , title: 'Should not show :)'848 });849 850 app.get('/video', function(req, res, next){851 res.local('close', '?>')852 res.local('title', 'Wahoo');853 res.render('video.ejs', { layout: false, title: 'keyboard cat' });854 });855 856 assert.response(app,857 { url: '/video' },858 { body: '<h1>keyboard cat</h1>' });859 },860 861 'test res.local() partials': function(){862 var app = create();863 864 app.set('view options', {865 site: 'My Cool Pets'866 });867 868 app.get('/pets', function(req, res, next){869 res.local('pets', ['Tobi']);870 next();871 });872 873 app.get('/pets', function(req, res, next){874 var pets;875 if (pets = res.local('pets')) {876 pets.push('Jane', 'Bandit');877 }878 next();879 });

made`str` localmgutzbefore adoptioneae1670

line 880why, one step back
880

Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f

lines 881–898why, one step back
881 app.get('/pets', function(req, res, next){
882 res.render('pets.jade');883 });884885 var html = [886 '<html>',887 '<body>',888 '<h1>My Cool Pets</h1>',889 '<p>We have 3 cool pets\n</p>',890 '<ul>',891 '<li>Tobi is the coolest of My Cool Pets</li>',892 '<li>Jane</li>',893 '<li>Bandit</li>',894 '</ul>',895 '</body>',896 '</html>'897 ].join('');898

made`str` localmgutzbefore adoptioneae1670

line 899why, one step back
899 assert.response(app,

Added res.local() for progressive view localsTj Holowaychukbefore adoption6b0d82f

lines 900–901why, one step back
900 { url: '/pets' },
901 { body: html });

using should / refactored testsTj Holowaychukbefore adoption643879f

line 902why, one step back
902 }

master is 2.0.0-preTj Holowaychukbefore adoptionce2a18f

line 903why, one step back
903};