Undefined in Config::set always unsets the value

This commit is contained in:
Ben Ogle
2014-09-25 12:37:02 -07:00
parent c6f7c75c8a
commit 6b4ce902ba
2 changed files with 22 additions and 4 deletions

View File

@@ -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 =

View File

@@ -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)