From 7ef6c5d9d7d4753a219d3ab35afae0d475430cae Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 23 Jul 2013 13:32:12 -0700 Subject: [PATCH] Unused config objects are finalized properly [GH-1877] --- CHANGELOG.md | 1 + lib/vagrant/config/v2/root.rb | 6 ++++++ test/unit/vagrant/config/v2/root_test.rb | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb2acb6fc..fb125f5d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ BUG FIXES: works properly despite misconfigured sudoers. [GH-1307] - Synced folder paths on Windows containing '\' are replaced with '/' internally so that they work properly. + - Unused config objects are finalized properly. [GH-1877] ## 1.2.4 (July 16, 2013) diff --git a/lib/vagrant/config/v2/root.rb b/lib/vagrant/config/v2/root.rb index 89009af9e..13ddc43d2 100644 --- a/lib/vagrant/config/v2/root.rb +++ b/lib/vagrant/config/v2/root.rb @@ -40,6 +40,12 @@ module Vagrant # the Vagrant system. The "!" signifies that this is expected to # mutate itself. def finalize! + @config_map.each do |key, klass| + if !@keys.has_key?(key) + @keys[key] = klass.new + end + end + @keys.each do |_key, instance| instance.finalize! end diff --git a/test/unit/vagrant/config/v2/root_test.rb b/test/unit/vagrant/config/v2/root_test.rb index d80806522..824215058 100644 --- a/test/unit/vagrant/config/v2/root_test.rb +++ b/test/unit/vagrant/config/v2/root_test.rb @@ -41,6 +41,24 @@ describe Vagrant::Config::V2::Root do } end + describe "finalization" do + it "should finalize un-used keys" do + foo_class = Class.new do + attr_accessor :foo + + def finalize! + @foo = "SET" + end + end + + map = { :foo => foo_class } + instance = described_class.new(map) + instance.finalize! + + instance.foo.foo.should == "SET" + end + end + describe "validation" do let(:instance) do map = { :foo => Object, :bar => Object }