summaryrefslogtreecommitdiffstats
path: root/spec/unit/network/http/handler.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-03-19 23:58:19 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-03-20 18:27:08 +1100
commit0179e945a7d402c90a333c8207243882af362e06 (patch)
treee977d49f50c7907a67799bd8d445f833f9c823ee /spec/unit/network/http/handler.rb
parenta497263d97229489dcc4341cc98ca3c75f116374 (diff)
downloadpuppet-0179e945a7d402c90a333c8207243882af362e06.tar.gz
puppet-0179e945a7d402c90a333c8207243882af362e06.tar.xz
puppet-0179e945a7d402c90a333c8207243882af362e06.zip
Fixing #1557 - Environments are now in REST URIs
This commit includes multiple, related changes, all in one commit because the whole thing was necessary to reach a functional tree again: * The URI starts with the environment, so: /production/certificate/foo /development/file_content/path/to/your/file * All REST handling is done by a single instance mounted at / for webrick and Mongrel, rather than having individual instances mounted at, say, /certificate. * All REST URI translation is done by an API module. Currently only the 'v1' module exists with no support for additional modules, but it's well-separated and will be easy to expand as we need it. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit/network/http/handler.rb')
-rwxr-xr-xspec/unit/network/http/handler.rb66
1 files changed, 36 insertions, 30 deletions
diff --git a/spec/unit/network/http/handler.rb b/spec/unit/network/http/handler.rb
index 85149b642..84b87025f 100755
--- a/spec/unit/network/http/handler.rb
+++ b/spec/unit/network/http/handler.rb
@@ -21,28 +21,13 @@ describe Puppet::Network::HTTP::Handler do
end
describe "when initializing" do
- before do
- Puppet::Indirector::Indirection.stubs(:model).returns "eh"
- end
-
it "should fail when no server type has been provided" do
- lambda { @handler.initialize_for_puppet :handler => "foo" }.should raise_error(ArgumentError)
+ lambda { @handler.initialize_for_puppet }.should raise_error(ArgumentError)
end
- it "should fail when no handler has been provided" do
- lambda { @handler.initialize_for_puppet :server => "foo" }.should raise_error(ArgumentError)
- end
-
- it "should set the handler and server type" do
- @handler.initialize_for_puppet :server => "foo", :handler => "bar"
+ it "should set server type" do
+ @handler.initialize_for_puppet("foo")
@handler.server.should == "foo"
- @handler.handler.should == "bar"
- end
-
- it "should use the indirector to find the appropriate model" do
- Puppet::Indirector::Indirection.expects(:model).with("bar").returns "mymodel"
- @handler.initialize_for_puppet :server => "foo", :handler => "bar"
- @handler.model.should == "mymodel"
end
end
@@ -59,9 +44,6 @@ describe Puppet::Network::HTTP::Handler do
@result = stub 'result', :render => "mytext"
- @handler.stubs(:model).returns @model_class
- @handler.stubs(:handler).returns :my_handler
-
stub_server_interface
end
@@ -82,7 +64,7 @@ describe Puppet::Network::HTTP::Handler do
@handler.expects(:http_method).with(@request).returns "mymethod"
@handler.expects(:params).with(@request).returns "myparams"
- @handler.expects(:uri2indirection).with("mypath", "myparams", "mymethod").returns stub("request", :method => :find)
+ @handler.expects(:uri2indirection).with("mymethod", "mypath", "myparams").returns stub("request", :method => :find)
@handler.stubs(:do_find)
@@ -115,7 +97,7 @@ describe Puppet::Network::HTTP::Handler do
describe "when finding a model instance" do
before do
- @irequest = stub 'indirection_request', :method => :find, :indirection_name => "my_handler", :options => {}, :key => "my_result"
+ @irequest = stub 'indirection_request', :method => :find, :indirection_name => "my_handler", :to_hash => {}, :key => "my_result", :model => @model_class
@model_class.stubs(:find).returns @result
@@ -123,6 +105,12 @@ describe Puppet::Network::HTTP::Handler do
Puppet::Network::FormatHandler.stubs(:format).returns @format
end
+ it "should use the indirection request to find the model class" do
+ @irequest.expects(:model).returns @model_class
+
+ @handler.do_find(@irequest, @request, @response)
+ end
+
it "should use the escaped request key" do
@model_class.expects(:find).with do |key, args|
key == "my_result"
@@ -131,7 +119,7 @@ describe Puppet::Network::HTTP::Handler do
end
it "should use a common method for determining the request parameters" do
- @irequest.stubs(:options).returns(:foo => :baz, :bar => :xyzzy)
+ @irequest.stubs(:to_hash).returns(:foo => :baz, :bar => :xyzzy)
@model_class.expects(:find).with do |key, args|
args[:foo] == :baz and args[:bar] == :xyzzy
end.returns @result
@@ -206,7 +194,7 @@ describe Puppet::Network::HTTP::Handler do
describe "when searching for model instances" do
before do
- @irequest = stub 'indirection_request', :method => :find, :indirection_name => "my_handler", :options => {}, :key => "key"
+ @irequest = stub 'indirection_request', :method => :find, :indirection_name => "my_handler", :to_hash => {}, :key => "key", :model => @model_class
@result1 = mock 'result1'
@result2 = mock 'results'
@@ -219,8 +207,14 @@ describe Puppet::Network::HTTP::Handler do
Puppet::Network::FormatHandler.stubs(:format).returns @format
end
+ it "should use the indirection request to find the model" do
+ @irequest.expects(:model).returns @model_class
+
+ @handler.do_search(@irequest, @request, @response)
+ end
+
it "should use a common method for determining the request parameters" do
- @irequest.stubs(:options).returns(:foo => :baz, :bar => :xyzzy)
+ @irequest.stubs(:to_hash).returns(:foo => :baz, :bar => :xyzzy)
@model_class.expects(:search).with do |key, args|
args[:foo] == :baz and args[:bar] == :xyzzy
end.returns @result
@@ -267,12 +261,18 @@ describe Puppet::Network::HTTP::Handler do
describe "when destroying a model instance" do
before do
- @irequest = stub 'indirection_request', :method => :destroy, :indirection_name => "my_handler", :options => {}, :key => "key"
+ @irequest = stub 'indirection_request', :method => :destroy, :indirection_name => "my_handler", :to_hash => {}, :key => "key", :model => @model_class
@result = stub 'result', :render => "the result"
@model_class.stubs(:destroy).returns @result
end
+ it "should use the indirection request to find the model" do
+ @irequest.expects(:model).returns @model_class
+
+ @handler.do_destroy(@irequest, @request, @response)
+ end
+
it "should use the escaped request key to destroy the instance in the model" do
@irequest.expects(:key).returns "foo bar"
@model_class.expects(:destroy).with do |key, args|
@@ -282,7 +282,7 @@ describe Puppet::Network::HTTP::Handler do
end
it "should use a common method for determining the request parameters" do
- @irequest.stubs(:options).returns(:foo => :baz, :bar => :xyzzy)
+ @irequest.stubs(:to_hash).returns(:foo => :baz, :bar => :xyzzy)
@model_class.expects(:destroy).with do |key, args|
args[:foo] == :baz and args[:bar] == :xyzzy
end
@@ -306,7 +306,7 @@ describe Puppet::Network::HTTP::Handler do
describe "when saving a model instance" do
before do
- @irequest = stub 'indirection_request', :method => :save, :indirection_name => "my_handler", :options => {}, :key => "key"
+ @irequest = stub 'indirection_request', :method => :save, :indirection_name => "my_handler", :to_hash => {}, :key => "key", :model => @model_class
@handler.stubs(:body).returns('my stuff')
@result = stub 'result', :render => "the result"
@@ -318,6 +318,12 @@ describe Puppet::Network::HTTP::Handler do
Puppet::Network::FormatHandler.stubs(:format).returns @format
end
+ it "should use the indirection request to find the model" do
+ @irequest.expects(:model).returns @model_class
+
+ @handler.do_save(@irequest, @request, @response)
+ end
+
it "should use the 'body' hook to retrieve the body of the request" do
@handler.expects(:body).returns "my body"
@model_class.expects(:convert_from).with { |format, body| body == "my body" }.returns @model_instance
@@ -332,7 +338,7 @@ describe Puppet::Network::HTTP::Handler do
end
it "should use a common method for determining the request parameters" do
- @irequest.stubs(:options).returns(:foo => :baz, :bar => :xyzzy)
+ @irequest.stubs(:to_hash).returns(:foo => :baz, :bar => :xyzzy)
@model_instance.expects(:save).with do |args|
args[:foo] == :baz and args[:bar] == :xyzzy
end