3 var assert = require('assert');
4 var express = require('..');
6 describe('config', function () {
7 describe('.set()', function () {
8 it('should set a value', function () {
10 app.set('foo', 'bar');
11 assert.equal(app.get('foo'), 'bar');
14 it('should set prototype values', function () {
16 app.set('hasOwnProperty', 42)
17 assert.strictEqual(app.get('hasOwnProperty'), 42)
20 it('should return the app', function () {
22 assert.equal(app.set('foo', 'bar'), app);
25 it('should return the app when undefined', function () {
27 assert.equal(app.set('foo', undefined), app);
30 it('should return set value', function () {
33 assert.strictEqual(app.set('foo'), 'bar')
36 it('should return undefined for prototype values', function () {
38 assert.strictEqual(app.set('hasOwnProperty'), undefined)
41 describe('"etag"', function(){
42 it('should throw on bad value', function(){
44 assert.throws(app.set.bind(app, 'etag', 42), /unknown value/);
47 it('should set "etag fn"', function(){
51 assert.equal(app.get('etag fn'), fn)
55 describe('"trust proxy"', function(){
56 it('should set "trust proxy fn"', function(){
59 app.set('trust proxy', fn)
60 assert.equal(app.get('trust proxy fn'), fn)
65 describe('.get()', function(){
66 it('should return undefined when unset', function(){
68 assert.strictEqual(app.get('foo'), undefined);
71 it('should return undefined for prototype values', function () {
73 assert.strictEqual(app.get('hasOwnProperty'), undefined)
76 it('should otherwise return the value', function(){
78 app.set('foo', 'bar');
79 assert.equal(app.get('foo'), 'bar');
82 describe('when mounted', function(){
83 it('should default to the parent app', function(){
87 app.set('title', 'Express');
89 assert.equal(blog.get('title'), 'Express');
92 it('should given precedence to the child', function(){
97 app.set('title', 'Express');
98 blog.set('title', 'Some Blog');
100 assert.equal(blog.get('title'), 'Some Blog');
103 it('should inherit "trust proxy" setting', function () {
105 var blog = express();
107 function fn() { return false }
109 app.set('trust proxy', fn);
110 assert.equal(app.get('trust proxy'), fn);
111 assert.equal(app.get('trust proxy fn'), fn);
115 assert.equal(blog.get('trust proxy'), fn);
116 assert.equal(blog.get('trust proxy fn'), fn);
119 it('should prefer child "trust proxy" setting', function () {
121 var blog = express();
123 function fn1() { return false }
124 function fn2() { return true }
126 app.set('trust proxy', fn1);
127 assert.equal(app.get('trust proxy'), fn1);
128 assert.equal(app.get('trust proxy fn'), fn1);
130 blog.set('trust proxy', fn2);
131 assert.equal(blog.get('trust proxy'), fn2);
132 assert.equal(blog.get('trust proxy fn'), fn2);
136 assert.equal(app.get('trust proxy'), fn1);
137 assert.equal(app.get('trust proxy fn'), fn1);
138 assert.equal(blog.get('trust proxy'), fn2);
139 assert.equal(blog.get('trust proxy fn'), fn2);
144 describe('.enable()', function(){
145 it('should set the value to true', function(){
147 assert.equal(app.enable('tobi'), app);
148 assert.strictEqual(app.get('tobi'), true);
151 it('should set prototype values', function () {
153 app.enable('hasOwnProperty')
154 assert.strictEqual(app.get('hasOwnProperty'), true)
158 describe('.disable()', function(){
159 it('should set the value to false', function(){
161 assert.equal(app.disable('tobi'), app);
162 assert.strictEqual(app.get('tobi'), false);
165 it('should set prototype values', function () {
167 app.disable('hasOwnProperty')
168 assert.strictEqual(app.get('hasOwnProperty'), false)
172 describe('.enabled()', function(){
173 it('should default to false', function(){
175 assert.strictEqual(app.enabled('foo'), false);
178 it('should return true when set', function(){
180 app.set('foo', 'bar');
181 assert.strictEqual(app.enabled('foo'), true);
184 it('should default to false for prototype values', function () {
186 assert.strictEqual(app.enabled('hasOwnProperty'), false)
190 describe('.disabled()', function(){
191 it('should default to true', function(){
193 assert.strictEqual(app.disabled('foo'), true);
196 it('should return false when set', function(){
198 app.set('foo', 'bar');
199 assert.strictEqual(app.disabled('foo'), false);
202 it('should default to true for prototype values', function () {
204 assert.strictEqual(app.disabled('hasOwnProperty'), true)