diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index f939bd0ec..4b0cc93b1 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -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 diff --git a/lib/vagrant/config/v1/loader.rb b/lib/vagrant/config/v1/loader.rb index 45b9e0ba3..910ae3dda 100644 --- a/lib/vagrant/config/v1/loader.rb +++ b/lib/vagrant/config/v1/loader.rb @@ -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 diff --git a/test/unit/vagrant/config/v1/loader_test.rb b/test/unit/vagrant/config/v1/loader_test.rb index a8dd85a47..e296a4972 100644 --- a/test/unit/vagrant/config/v1/loader_test.rb +++ b/test/unit/vagrant/config/v1/loader_test.rb @@ -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 diff --git a/vagrant.gemspec b/vagrant.gemspec index 661d9b69b..1f419593a 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -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