Handle a source but no selector in ::unset

This commit is contained in:
Max Brunsfeld
2014-12-26 17:24:27 -08:00
parent 2949ebfe86
commit d508d1eedf
2 changed files with 12 additions and 6 deletions

View File

@@ -193,8 +193,14 @@ describe "Config", ->
atom.config.unset('a.c')
expect(atom.config.save.callCount).toBe 1
it "throws when called with a source but no scope", ->
expect(-> atom.config.unset("a.b", source: "the-source")).toThrow()
describe "when a 'source' and no 'scopeSelector' is given", ->
it "removes all scoped settings with the given source", ->
atom.config.set("foo.bar.baz", 1, scopeSelector: ".a", source: "source-a")
atom.config.set("foo.bar.quux", 2, scopeSelector: ".b", source: "source-a")
expect(atom.config.get("foo.bar", scope: [".a.b"])).toEqual(baz: 1, quux: 2)
atom.config.unset(null, source: "source-a")
expect(atom.config.get("foo.bar", scope: [".a"])).toEqual(baz: 0, ok: 0)
describe "when a 'scopeSelector' is given", ->
it "restores the global default when no scoped default set", ->

View File

@@ -585,9 +585,6 @@ class Config
else
{scopeSelector, source} = options ? {}
if source and not scopeSelector
throw new Error("::unset with a 'source' and no 'sourceSelector' is not yet implemented!")
source ?= @getUserConfigPath()
if scopeSelector?
@@ -603,7 +600,10 @@ class Config
@scopedSettingsStore.removePropertiesForSource(source)
@emitChangeEvent()
else
@set(keyPath, _.valueForKeyPath(@defaultSettings, keyPath))
@scopedSettingsStore.removePropertiesForSource(source)
if keyPath?
@set(keyPath, _.valueForKeyPath(@defaultSettings, keyPath))
# Extended: Get an {Array} of all of the `source` {String}s with which
# settings have been added via {::set}.