From 6b4ce902baebaafd8a397f1a99ebcd7fb00bc42c Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 25 Sep 2014 12:37:02 -0700 Subject: [PATCH] Undefined in Config::set always unsets the value --- spec/config-spec.coffee | 17 +++++++++++++++++ src/config.coffee | 9 +++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/spec/config-spec.coffee b/spec/config-spec.coffee index 4e7aad526..4c006a24e 100644 --- a/spec/config-spec.coffee +++ b/spec/config-spec.coffee @@ -577,6 +577,23 @@ describe "Config", -> atom.config.set('foo.bar.anInt', 'cats') expect(atom.config.get('foo.bar.anInt')).toBe 'cats' + describe 'when the value has an "string" and "boolean" type', -> + beforeEach -> + schema = + type: ['string', 'boolean'] + default: 'def' + atom.config.setSchema('foo.bar', schema) + + it 'can set a string, a boolean, and unset', -> + atom.config.set('foo.bar', 'ok') + expect(atom.config.get('foo.bar')).toBe 'ok' + + atom.config.set('foo.bar', false) + expect(atom.config.get('foo.bar')).toBe false + + atom.config.set('foo.bar', undefined) + expect(atom.config.get('foo.bar')).toBe 'def' + describe 'when the value has a "number" type', -> beforeEach -> schema = diff --git a/src/config.coffee b/src/config.coffee index d5fe28dd5..930d2d419 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -381,10 +381,11 @@ class Config # * `true` if the value was set. # * `false` if the value was not able to be coerced to the type specified in the setting's schema. set: (keyPath, value) -> - try - value = @scrubValue(keyPath, value) - catch e - return false + unless value == undefined + try + value = @scrubValue(keyPath, value) + catch e + return false if @get(keyPath) isnt value defaultValue = _.valueForKeyPath(@defaultSettings, keyPath)