2 var assert = require('assert');
3 var express = require('..');
5 describe('config', function () {
6 describe('.set()', function () {
7 it('should set a value', function () {
10 assert.equal(app.get('foo'), 'bar');
13 it('should return the app', function () {
15 assert.equal(app.set('foo', 'bar'), app);
18 it('should return the app when undefined', function () {
20 assert.equal(app.set('foo', undefined), app);
23 describe('"etag"', function(){
24 it('should throw on bad value', function(){
26 assert.throws(app.set.bind(app, 'etag', 42), /unknown value/);
29 it('should set "etag fn"', function(){
33 assert.equal(app.get('etag fn'), fn)
37 describe('"trust proxy"', function(){
38 it('should set "trust proxy fn"', function(){
41 app.set('trust proxy', fn)
42 assert.equal(app.get('trust proxy fn'), fn)
47 describe('.get()', function(){
48 it('should return undefined when unset', function(){
50 assert.strictEqual(app.get('foo'), undefined);
53 it('should otherwise return the value', function(){
55 app.set('foo', 'bar');
56 assert.equal(app.get('foo'), 'bar');
59 describe('when mounted', function(){
60 it('should default to the parent app', function(){
64 app.set('title', 'Express');
66 assert.equal(blog.get('title'), 'Express');
69 it('should given precedence to the child', function(){
74 app.set('title', 'Express');
75 blog.set('title', 'Some Blog');
77 assert.equal(blog.get('title'), 'Some Blog');
80 it('should inherit "trust proxy" setting', function () {
84 function fn() { return false }
86 app.set('trust proxy', fn);
87 assert.equal(app.get('trust proxy'), fn);
88 assert.equal(app.get('trust proxy fn'), fn);
92 assert.equal(blog.get('trust proxy'), fn);
93 assert.equal(blog.get('trust proxy fn'), fn);
96 it('should prefer child "trust proxy" setting', function () {
100 function fn1() { return false }
101 function fn2() { return true }
103 app.set('trust proxy', fn1);
104 assert.equal(app.get('trust proxy'), fn1);
105 assert.equal(app.get('trust proxy fn'), fn1);
107 blog.set('trust proxy', fn2);
108 assert.equal(blog.get('trust proxy'), fn2);
109 assert.equal(blog.get('trust proxy fn'), fn2);
113 assert.equal(app.get('trust proxy'), fn1);
114 assert.equal(app.get('trust proxy fn'), fn1);
115 assert.equal(blog.get('trust proxy'), fn2);
116 assert.equal(blog.get('trust proxy fn'), fn2);
121 describe('.enable()', function(){
122 it('should set the value to true', function(){
124 assert.equal(app.enable('tobi'), app);
125 assert.strictEqual(app.get('tobi'), true);
129 describe('.disable()', function(){
130 it('should set the value to false', function(){
132 assert.equal(app.disable('tobi'), app);
133 assert.strictEqual(app.get('tobi'), false);
137 describe('.enabled()', function(){
138 it('should default to false', function(){
140 assert.strictEqual(app.enabled('foo'), false);
143 it('should return true when set', function(){
145 app.set('foo', 'bar');
146 assert.strictEqual(app.enabled('foo'), true);
150 describe('.disabled()', function(){
151 it('should default to true', function(){
153 assert.strictEqual(app.disabled('foo'), true);
156 it('should return false when set', function(){
158 app.set('foo', 'bar');
159 assert.strictEqual(app.disabled('foo'), false);