diff --git a/lib/nconf/provider.js b/lib/nconf/provider.js index b9c1125..7ca4678 100644 --- a/lib/nconf/provider.js +++ b/lib/nconf/provider.js @@ -26,9 +26,21 @@ var Provider = exports.Provider = function (options) { // specified `type`. // Provider.prototype.use = function (type, options) { - if (!this.store || type.toLowerCase() !== this.store.type) { + var self = this; + options = options || {}; + + function sameOptions () { + return Object.keys(options).every(function (key) { + return options[key] === self.store[key]; + }); + } + + if (!this.store || type.toLowerCase() !== this.store.type + || !sameOptions()) { this.store = stores.create(type, options); } + + return this; }; // diff --git a/test/provider-test.js b/test/provider-test.js new file mode 100644 index 0000000..356945b --- /dev/null +++ b/test/provider-test.js @@ -0,0 +1,32 @@ +/* + * file-store-test.js: Tests for the nconf File store. + * + * (C) 2011, Charlie Robbins + * + */ + +var fs = require('fs'), + path = require('path'), + vows = require('vows'), + assert = require('assert'), + nconf = require('../lib/nconf') + +var first = '/path/to/file1', + second = '/path/to/file2'; + +vows.describe('nconf/provider').addBatch({ + "When using an instance of nconf.Provier": { + "calling the use() method with the same store type and different options": { + topic: new nconf.Provider().use('file', { file: first }), + "should use a new instance of the store type": function (provider) { + var old = provider.store; + + assert.equal(provider.store.file, first); + provider.use('file', { file: second }); + + assert.notStrictEqual(old, provider.store); + assert.equal(provider.store.file, second); + } + } + } +}).export(module); \ No newline at end of file