core: call #state in any #action call [GH-4513]

This commit is contained in:
Mitchell Hashimoto 2014-10-23 12:20:16 -07:00
parent bb22a37ed1
commit f0a73c7c05
3 changed files with 29 additions and 1 deletions

View File

@ -29,6 +29,7 @@ BUG FIXES:
- core: Box downloads recognize more complex content types that include
"application/json" [GH-4525]
- core: If all sub-machines are `autostart: false`, don't start any. [GH-4552]
- core: Update global-status state in more cases. [GH-4513]
- commands/box: `--cert` flag works properly. [GH-4691]
- command/docker-logs: Won't crash if container is removed. [GH-3990]
- command/docker-run: Synced folders will be attached properly. [GH-3873]

View File

@ -178,7 +178,19 @@ module Vagrant
provider: @provider.to_s
end
action_raw(name, callable, extra_env)
# Call the action
result = action_raw(name, callable, extra_env)
# Call the state method so that we update our index state. Don't
# worry about exceptions here, since we just care about updating
# the cache.
begin
# Called for side effects
self.state
rescue Errors::VagrantError
end
return result
end
rescue Errors::EnvironmentLockedError
raise Errors::MachineActionLockedError,

View File

@ -216,6 +216,10 @@ describe Vagrant::Machine do
end
describe "#action" do
before do
provider.stub(state: Vagrant::MachineState.new(:foo, "", ""))
end
it "should be able to run an action that exists" do
action_name = :up
called = false
@ -266,6 +270,17 @@ describe Vagrant::Machine do
expect { instance.action(action_name) }.
to raise_error(Vagrant::Errors::UnimplementedProviderAction)
end
it "calls #state to update the machine index" do
action_name = :up
called = false
callable = lambda { |_env| called = true }
expect(provider).to receive(:action).with(action_name).and_return(callable)
expect(instance).to receive(:state)
instance.action(:up)
expect(called).to be
end
end
describe "#action_raw" do