Skip to content
Myr

fix app.locals.use() when mounting apps

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

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 93f1cec · Browse files · 4 files+63 added−1 removed
This commit

State

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

Diff stats

4 files+63 added−1 removed

  • tests:+60 added−0 removed
  • other:+3 added−1 removed

4 files+63 added−1 removed

modified:lib/application.js+1 added-1 removed
61 unmodified lines
62 this.on('mount', function(parent){63 this.request.__proto__ = parent.request;64 this.response.__proto__ = parent.response;65 this.engines.__proto__ = parent.engines;66 this.viewCallbacks = parent.viewCallbacks.slice(0);66 parent.viewCallbacks = parent.viewCallbacks.concat(this.viewCallbacks);67 });6869 // router70 this._router = new Router(this);
462 unmodified lines
modified:test/app.locals.use.js+27 added
modified:test/res.locals.use.js+33 added
98 unmodified lines
99 res.text.should.equal('<p>tobi ibot is a ferret</p>');100 done();101 })102 })103104 it('should work when mounted', function(done){105 var app = express();106 var pet = express();107108 app.set('views', __dirname + '/fixtures');109110 app.locals.first = 'tobi';111 112 app.use(function(req, res, next){113 res.locals.use(function(){114 res.locals.last = 'holowaychuk';115 });116 next();117 });118119 pet.use(function(req, res, next){120 res.locals.use(function(){121 res.locals.species = 'ferret';122 });123 next();124 });125 126 app.use(function(req, res){127 res.render('pet.jade');128 });129130 app.use(pet);131132 request(app)133 .get('/')134 .expect('<p>tobi holowaychuk is a ferret</p>', done);135 })136 })137})
modified:Makefile+2 added
12MOCHA_OPTS=3REPORTER = dot45docs: docs/express.md6
10 unmodified lines
1718test-unit:19 @NODE_ENV=test ./node_modules/.bin/mocha \20 --reporter $(REPORTER) \21 $(MOCHA_OPTS) \22 --bail2324test-acceptance:25 @NODE_ENV=test ./node_modules/.bin/mocha \
17 unmodified lines