Merge pull request from SchoonologyRRL/patch-1

Updated Memory.merge to handle null values
This commit is contained in:
Charlie Robbins 2012-12-20 22:56:54 -08:00
commit 818526ca62
4 changed files with 12 additions and 3 deletions
lib/nconf/stores
test

View file

@ -157,7 +157,7 @@ Memory.prototype.merge = function (key, value) {
// If the key is not an `Object` or is an `Array`, // If the key is not an `Object` or is an `Array`,
// then simply set it. Merging is for Objects. // then simply set it. Merging is for Objects.
// //
if (typeof value !== 'object' || Array.isArray(value)) { if (typeof value !== 'object' || Array.isArray(value) || value === null) {
return this.set(key, value); return this.set(key, value);
} }

View file

@ -12,5 +12,8 @@
"first": 1, "first": 1,
"second": 2 "second": 2
} }
},
"unicorn": {
"exists": true
} }
} }

View file

@ -5,5 +5,6 @@
"something4": true "something4": true
}, },
"dates": true, "dates": true,
"elderberries": true "elderberries": true,
} "unicorn": null
}

View file

@ -84,6 +84,11 @@ vows.describe('nconf/provider').addBatch({
provider.merge(override); provider.merge(override);
helpers.assertMerged(null, provider.stores.file.store); helpers.assertMerged(null, provider.stores.file.store);
assert.equal(provider.stores.file.store.candy.something, 'file1'); assert.equal(provider.stores.file.store.candy.something, 'file1');
},
"should merge Objects over null": function (provider) {
provider.load();
provider.merge(override);
assert.equal(provider.stores.file.store.unicorn.exists, true);
} }
} }
} }