Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix app.locals.use() when mounting apps

  • Loading branch information...
commit 78845e7d231692054b526ee3956ef5768413621d 1 parent 93f1cec
@tj tj authored
View
2  Makefile
@@ -1,4 +1,5 @@
+MOCHA_OPTS=
REPORTER = dot
docs: docs/express.md
@@ -17,6 +18,7 @@ test: test-unit test-acceptance
test-unit:
@NODE_ENV=test ./node_modules/.bin/mocha \
--reporter $(REPORTER) \
+ $(MOCHA_OPTS) \
--bail
test-acceptance:
View
2  lib/application.js
@@ -63,7 +63,7 @@ app.defaultConfiguration = function(){
this.request.__proto__ = parent.request;
this.response.__proto__ = parent.response;
this.engines.__proto__ = parent.engines;
- this.viewCallbacks = parent.viewCallbacks.slice(0);
+ parent.viewCallbacks = parent.viewCallbacks.concat(this.viewCallbacks);
});
// router
View
27 test/app.locals.use.js
@@ -83,5 +83,32 @@ describe('app', function(){
.get('/')
.expect('<p>tobi ibot is a ferret</p>', done);
})
+
+ it('should work when mounted', function(done){
+ var app = express();
+ var pet = express();
+
+ app.set('views', __dirname + '/fixtures');
+
+ app.locals.first = 'tobi';
+
+ app.locals.use(function(req, res){
+ res.locals.last = 'holowaychuk';
+ });
+
+ pet.locals.use(function(req, res){
+ res.locals.species = 'ferret';
+ });
+
+ app.use(function(req, res){
+ res.render('pet.jade');
+ });
+
+ app.use(pet);
+
+ request(app)
+ .get('/')
+ .expect('<p>tobi holowaychuk is a ferret</p>', done);
+ })
})
})
View
33 test/res.locals.use.js
@@ -100,5 +100,38 @@ describe('res', function(){
done();
})
})
+
+ it('should work when mounted', function(done){
+ var app = express();
+ var pet = express();
+
+ app.set('views', __dirname + '/fixtures');
+
+ app.locals.first = 'tobi';
+
+ app.use(function(req, res, next){
+ res.locals.use(function(){
+ res.locals.last = 'holowaychuk';
+ });
+ next();
+ });
+
+ pet.use(function(req, res, next){
+ res.locals.use(function(){
+ res.locals.species = 'ferret';
+ });
+ next();
+ });
+
+ app.use(function(req, res){
+ res.render('pet.jade');
+ });
+
+ app.use(pet);
+
+ request(app)
+ .get('/')
+ .expect('<p>tobi holowaychuk is a ferret</p>', done);
+ })
})
})

0 comments on commit 78845e7

Please sign in to comment.
Something went wrong with that request. Please try again.