General validation middleware
This commit is contained in:
parent
dcb06a0e43
commit
82d73ebe3c
|
@ -0,0 +1,19 @@
|
||||||
|
module Vagrant
|
||||||
|
class Action
|
||||||
|
module General
|
||||||
|
# Simply validates the configuration of the current Vagrant
|
||||||
|
# environment.
|
||||||
|
class Validate
|
||||||
|
def initialize(app, env)
|
||||||
|
@app = app
|
||||||
|
@env = env
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
@env["config"].validate! if !@env.has_key?("validate") || @env["validate"]
|
||||||
|
@app.call(@env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,31 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class ValidateGeneralActionTest < Test::Unit::TestCase
|
||||||
|
setup do
|
||||||
|
@klass = Vagrant::Action::General::Validate
|
||||||
|
@app, @env = action_env
|
||||||
|
end
|
||||||
|
|
||||||
|
should "initialize fine" do
|
||||||
|
@klass.new(@app, @env)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "validate and call up" do
|
||||||
|
@instance = @klass.new(@app, @env)
|
||||||
|
|
||||||
|
seq = sequence("seq")
|
||||||
|
@env["config"].expects(:validate!).once.in_sequence(seq)
|
||||||
|
@app.expects(:call).with(@env).once.in_sequence(seq)
|
||||||
|
@instance.call(@env)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not validate if env says not to" do
|
||||||
|
@env["validate"] = false
|
||||||
|
@instance = @klass.new(@app, @env)
|
||||||
|
|
||||||
|
seq = sequence("seq")
|
||||||
|
@env["config"].expects(:validate!).never
|
||||||
|
@app.expects(:call).with(@env).once.in_sequence(seq)
|
||||||
|
@instance.call(@env)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue