Call properly modifies original environment

This commit is contained in:
Mitchell Hashimoto 2013-02-06 18:36:05 -08:00
parent 4a1a990491
commit cd3d2a1e8c
5 changed files with 16 additions and 15 deletions

View File

@ -2,7 +2,6 @@ require 'vagrant/action/builder'
module Vagrant
module Action
autoload :Environment, 'vagrant/action/environment'
autoload :Runner, 'vagrant/action/runner'
autoload :Warden, 'vagrant/action/warden'

View File

@ -50,8 +50,11 @@ module Vagrant
@child_app = builder.to_app(new_env)
final_env = runner.run(@child_app, new_env)
# Merge the environment into our original environment
env.merge!(final_env)
# Call the next step using our final environment
@app.call(final_env)
@app.call(env)
end
def recover(env)

View File

@ -1,12 +0,0 @@
require 'vagrant/util/hash_with_indifferent_access'
module Vagrant
module Action
# Represents an action environment which is what is passed
# to the `call` method of each action. This environment contains
# some helper methods for accessing the environment as well
# as being a hash, to store any additional options.
class Environment < Util::HashWithIndifferentAccess
end
end
end

View File

@ -23,7 +23,7 @@ module Vagrant
raise ArgumentError, "Argument to run must be a callable object or registered action." if !callable || !callable.respond_to?(:call)
# Create the initial environment with the options given
environment = Environment.new
environment = {}
environment.merge!(@globals)
environment.merge!(@lazy_globals.call) if @lazy_globals
environment.merge!(options || {})

View File

@ -18,6 +18,17 @@ describe Vagrant::Action::Builtin::Call do
received.should == "value"
end
it "should update the original env with any changes" do
callable = lambda { |env| }
next_step = lambda { |env| env[:inner] = true }
described_class.new(app, env, callable) do |_env, builder|
builder.use next_step
end.call(env)
env[:inner].should == true
end
it "should call the callable with the original environment" do
received = nil
callable = lambda { |env| received = env[:foo] }