V1 config loader loads upgradable config if not V1

This is to prepare for the upcoming V2 configuration. When we're in V2,
we only want to load _upgradable_ configuration keys.
This commit is contained in:
Mitchell Hashimoto 2012-11-03 21:54:32 -07:00
parent 399437e758
commit 0ca783e8d1
4 changed files with 51 additions and 15 deletions

View File

@ -25,6 +25,7 @@ module Vagrant
# current version is always considered to be the last version in this
# list.
VERSIONS_ORDER = ["1"]
CURRENT_VERSION = VERSIONS_ORDER.last
# This is the method which is called by all Vagrantfiles to configure Vagrant.
# This method expects a block which accepts a single argument representing

View File

@ -84,10 +84,16 @@ module Vagrant
protected
def self.new_root_object
# Get all the registered configuration objects and use them.
config_map = {}
Vagrant.plugin("1").manager.config.each do |key, klass|
config_map[key] = klass
# Get all the registered configuration objects and use them. If
# we're currently on version 1, then we load all the config objects,
# otherwise we load only the upgrade safe ones, since we're
# obviously being loaded for an upgrade.
config_map = nil
plugin_manager = Vagrant.plugin("1").manager
if Config::CURRENT_VERSION == "1"
config_map = plugin_manager.config
else
config_map = plugin_manager.config_upgrade_safe
end
# Create the configuration root object

View File

@ -1,3 +1,5 @@
require "ostruct"
require File.expand_path("../../../../base", __FILE__)
describe Vagrant::Config::V1::Loader do
@ -8,12 +10,44 @@ describe Vagrant::Config::V1::Loader do
result = described_class.init
result.should be_kind_of(Vagrant::Config::V1::Root)
end
it "returns an object with all configuration keys loaded if V1" do
# Make sure we're version 1
stub_const("Vagrant::Config::CURRENT_VERSION", "1")
# Register some config classes.
register_plugin do |p|
p.config("foo") { OpenStruct }
p.config("bar", true) { OpenStruct }
end
# Test that we have all keys
result = described_class.init
result.foo.should be_kind_of(OpenStruct)
result.bar.should be_kind_of(OpenStruct)
end
it "returns only upgradable config objects if not V1" do
# Make sure we're NOT version 1
stub_const("Vagrant::Config::CURRENT_VERSION", "2")
# Register some config classes.
register_plugin do |p|
p.config("foo") { OpenStruct }
p.config("bar", true) { OpenStruct }
end
# Test that we have all keys
result = described_class.init
result.bar.should be_kind_of(OpenStruct)
expect { result.foo }.to raise_error(NoMethodError)
end
end
describe "finalizing" do
it "should call `#finalize` on the configuration object" do
# Register a plugin for our test
plugin_class = register_plugin do |plugin|
register_plugin do |plugin|
plugin.name "test"
plugin.config "foo" do
Class.new do
@ -44,13 +78,8 @@ describe Vagrant::Config::V1::Loader do
describe "loading" do
it "should configure with all plugin config keys loaded" do
# Register a plugin for our test
plugin_class = register_plugin do |plugin|
plugin.name "test"
plugin.config "foo" do
Class.new do
attr_accessor :bar
end
end
register_plugin do |plugin|
plugin.config("foo") { OpenStruct }
end
# Create the proc we're testing

View File

@ -28,9 +28,9 @@ Gem::Specification.new do |s|
s.add_development_dependency "minitest", "~> 2.5.1"
s.add_development_dependency "mocha"
#s.add_development_dependency "sys-proctable", "~> 0.9.0"
s.add_development_dependency "rspec-core", "~> 2.8.0"
s.add_development_dependency "rspec-expectations", "~> 2.8.0"
s.add_development_dependency "rspec-mocks", "~> 2.8.0"
s.add_development_dependency "rspec-core", "~> 2.11.0"
s.add_development_dependency "rspec-expectations", "~> 2.11.0"
s.add_development_dependency "rspec-mocks", "~> 2.11.0"
s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f[/^bin\/(.*)/, 1]}.compact