mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Reset all user config values when the schema changes.
This commit is contained in:
@@ -1106,6 +1106,44 @@ describe "Config", ->
|
||||
expect(atom.config.get('foo.bar.str', scope: ['.source.js'])).toBe 'omg'
|
||||
expect(atom.config.get('foo.bar.str', scope: ['.source.coffee'])).toBe 'ok'
|
||||
|
||||
describe 'when a schema is added after config values have been set', ->
|
||||
schema = null
|
||||
beforeEach ->
|
||||
schema =
|
||||
type: 'object'
|
||||
properties:
|
||||
int:
|
||||
type: 'integer'
|
||||
default: 2
|
||||
|
||||
it 'the values set respect the new schema', ->
|
||||
expect(atom.config.set('foo.bar.int', 'nope')).toBe true
|
||||
expect(atom.config.set('foo.bar.int', 'notanint', scopeSelector: '.source.js')).toBe true
|
||||
expect(atom.config.set('foo.bar.int', 23, scopeSelector: '.source.coffee')).toBe true
|
||||
expect(atom.config.get('foo.bar.int')).toBe 'nope'
|
||||
expect(atom.config.get('foo.bar.int', scope: ['.source.js'])).toBe 'notanint'
|
||||
expect(atom.config.get('foo.bar.int', scope: ['.source.coffee'])).toBe 23
|
||||
|
||||
atom.config.setSchema('foo.bar', schema)
|
||||
|
||||
expect(atom.config.get('foo.bar.int')).toBe 2
|
||||
expect(atom.config.get('foo.bar.int', scope: ['.source.js'])).toBe 2
|
||||
expect(atom.config.get('foo.bar.int', scope: ['.source.coffee'])).toBe 23
|
||||
|
||||
it 'doesnt mess it up', ->
|
||||
expect(atom.config.set('foo.bar.int', 10)).toBe true
|
||||
expect(atom.config.set('foo.bar.int', 15, scopeSelector: '.source.js')).toBe true
|
||||
expect(atom.config.set('foo.bar.int', 23, scopeSelector: '.source.coffee')).toBe true
|
||||
expect(atom.config.get('foo.bar.int')).toBe 10
|
||||
expect(atom.config.get('foo.bar.int', scope: ['.source.js'])).toBe 15
|
||||
expect(atom.config.get('foo.bar.int', scope: ['.source.coffee'])).toBe 23
|
||||
|
||||
atom.config.setSchema('foo.bar', schema)
|
||||
|
||||
expect(atom.config.get('foo.bar.int')).toBe 10
|
||||
expect(atom.config.get('foo.bar.int', scope: ['.source.js'])).toBe 15
|
||||
expect(atom.config.get('foo.bar.int', scope: ['.source.coffee'])).toBe 23
|
||||
|
||||
describe 'when the value has an "integer" type', ->
|
||||
beforeEach ->
|
||||
schema =
|
||||
|
||||
@@ -797,6 +797,7 @@ class Config
|
||||
_.extend rootSchema, schema
|
||||
@setDefaults(keyPath, @extractDefaultsFromSchema(schema))
|
||||
@setScopedDefaultsFromSchema(keyPath, schema)
|
||||
@resetForSchemaChange()
|
||||
|
||||
load: ->
|
||||
@initializeConfigDirectory()
|
||||
@@ -1002,6 +1003,20 @@ class Config
|
||||
value = @constructor.executeSchemaEnforcers(keyPath, value, schema) if schema = @getSchema(keyPath)
|
||||
value
|
||||
|
||||
# When the schema is changed / added, there may be values set in the config
|
||||
# that do not conform to the config. This will reset make them conform.
|
||||
resetForSchemaChange: (source=@getUserConfigPath()) ->
|
||||
settings = @settings
|
||||
@settings = null
|
||||
@set(null, settings, {save: false})
|
||||
|
||||
priority = @priorityForSource(source)
|
||||
selectorsAndSettings = @scopedSettingsStore.propertiesForSource(source)
|
||||
@scopedSettingsStore.removePropertiesForSource(source)
|
||||
for scopeSelector, settings of selectorsAndSettings
|
||||
@set(null, settings, {scopeSelector, source, priority, save: false}) if settings?
|
||||
return
|
||||
|
||||
###
|
||||
Section: Private Scoped Settings
|
||||
###
|
||||
|
||||
Reference in New Issue
Block a user