Box.find sets environment of found box

This commit is contained in:
Mitchell Hashimoto 2010-03-20 01:04:56 -07:00
parent 36648e7a12
commit 1d518e2693
4 changed files with 10 additions and 9 deletions

View File

@ -81,7 +81,7 @@ module Vagrant
# @return [Box] Instance of {Box} representing the box found
def find(env, name)
return nil unless File.directory?(directory(env, name))
new(name)
new(env, name)
end
# Adds a new box with given name from the given URI. This method
@ -115,8 +115,9 @@ module Vagrant
#
# **Note:** This method does not actually _create_ the box, but merely
# returns a new, abstract representation of it. To add a box, see {#add}.
def initialize(name=nil)
def initialize(env=nil, name=nil)
@name = name
@env = env
end
# Returns path to the OVF file of the box. The OVF file is an open

View File

@ -167,7 +167,6 @@ module Vagrant
return unless root_path
@box = Box.find(self, config.vm.box) if config.vm.box
@box.env = self if @box
end
# Loads the persisted VM (if it exists) for this environment.

View File

@ -71,6 +71,13 @@ class BoxTest < Test::Unit::TestCase
assert result
assert_equal @name, result.name
end
should "return a box object with the proper env set" do
File.expects(:directory?).with(@dir).once.returns(true)
result = Vagrant::Box.find(@env, @name)
assert result
assert_equal @env, result.env
end
end
context "adding" do

View File

@ -345,12 +345,6 @@ class EnvironmentTest < Test::Unit::TestCase
@env.load_box!
assert @box.equal?(@env.box)
end
should "set the environment of the box" do
@box.expects(:env=).with(@env).once
Vagrant::Box.expects(:find).with(@env, @env.config.vm.box).once.returns(@box)
@env.load_box!
end
end
context "loading the UUID out from the persisted dotfile" do