diff options
| author | Rick Bradley <rick@rickbradley.com> | 2007-10-16 10:15:14 -0500 |
|---|---|---|
| committer | Rick Bradley <rick@rickbradley.com> | 2007-10-16 10:15:14 -0500 |
| commit | c06edda4c94ef9aa685ed44d7031bb39c4a2b0cc (patch) | |
| tree | c8fedbe14686ac205c212258ac526cd6483982c8 /spec/unit/network/http | |
| parent | ab4c7fa825e0d1f702adc215c7ff6d445d3b6559 (diff) | |
| download | puppet-c06edda4c94ef9aa685ed44d7031bb39c4a2b0cc.tar.gz puppet-c06edda4c94ef9aa685ed44d7031bb39c4a2b0cc.tar.xz puppet-c06edda4c94ef9aa685ed44d7031bb39c4a2b0cc.zip | |
First pass through initializers of {mongrel, webrick} REST handlers; hooks into Indirection to look up models from indirected names.
Diffstat (limited to 'spec/unit/network/http')
| -rw-r--r-- | spec/unit/network/http/mongrel.rb | 8 | ||||
| -rw-r--r-- | spec/unit/network/http/mongrel/rest.rb | 46 | ||||
| -rw-r--r-- | spec/unit/network/http/mongrel/xmlrpc.rb | 0 | ||||
| -rw-r--r-- | spec/unit/network/http/webrick.rb | 8 | ||||
| -rw-r--r-- | spec/unit/network/http/webrick/rest.rb | 46 | ||||
| -rw-r--r-- | spec/unit/network/http/webrick/xmlrpc.rb | 0 |
6 files changed, 98 insertions, 10 deletions
diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb index 161080109..3364efb92 100644 --- a/spec/unit/network/http/mongrel.rb +++ b/spec/unit/network/http/mongrel.rb @@ -64,11 +64,9 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do @listen_params[:protocols].each do |protocol| mock_handler = mock("handler instance for [#{protocol}]") mock_handler_class = mock("handler class for [#{protocol}]") - @listen_params[:handlers].each do |handler| - mock_handler_class.expects(:new).with {|args| - args[:server] == @mock_mongrel and args[:handler] == handler - }.returns(mock_handler) - end + mock_handler_class.expects(:new).with {|args| + args[:server] == @mock_mongrel and args[:handlers] == @listen_params[:handlers] + }.returns(mock_handler) @server.expects(:class_for_protocol).with(protocol).at_least_once.returns(mock_handler_class) end @server.listen(@listen_params) diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb new file mode 100644 index 000000000..4a6524ef6 --- /dev/null +++ b/spec/unit/network/http/mongrel/rest.rb @@ -0,0 +1,46 @@ +#!/usr/bin/env ruby +# +# Created by Rick Bradley on 2007-10-16. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../../../spec_helper' +require 'puppet/network/http' + +describe Puppet::Network::HTTP::MongrelREST, "when initializing" do + before do + @mock_mongrel = mock('Mongrel server') + @params = { :server => @mock_mongrel, :handlers => [ :foo ] } + end + + it "should require access to a Mongrel server" do + Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params.delete_if {|k,v| :server == k })}.should raise_error(ArgumentError) + end + + it "should require at least one indirection name" do + Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params.delete_if {|k,v| :handlers == k })}.should raise_error(ArgumentError) + end + + it "should look up the indirection model from the indirection name" do + mock_model = mock('indirected model') + Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(mock_model) + Puppet::Network::HTTP::MongrelREST.new(@params) + end + + it "should fail if a handler is not indirected" do + Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(nil) + Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params) }.should raise_error(ArgumentError) + end + + it "should register a listener for each indirection with the provided Mongrel server" +end + +describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do + it "should unpack request information from Mongrel" + it "should unpack parameters from the request for passing to controller methods" + it "should call the controller find method if the request represents a singular HTTP GET" + it "should call the controller search method if the request represents a plural HTTP GET" + it "should call the controller destroy method if the request represents an HTTP DELETE" + it "should call the controller save method if the request represents an HTTP PUT" + it "should serialize the result from the controller method for return back to Mongrel" + it "should serialize a controller expection result for return back to Mongrel" +end diff --git a/spec/unit/network/http/mongrel/xmlrpc.rb b/spec/unit/network/http/mongrel/xmlrpc.rb new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/spec/unit/network/http/mongrel/xmlrpc.rb diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb index 81b2a0fa9..4bf742b6e 100644 --- a/spec/unit/network/http/webrick.rb +++ b/spec/unit/network/http/webrick.rb @@ -64,11 +64,9 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do @listen_params[:protocols].each do |protocol| mock_handler = mock("handler instance for [#{protocol}]") mock_handler_class = mock("handler class for [#{protocol}]") - @listen_params[:handlers].each do |handler| - mock_handler_class.expects(:new).with {|args| - args[:server] == @mock_webrick and args[:handler] == handler - }.returns(mock_handler) - end + mock_handler_class.expects(:new).with {|args| + args[:server] == @mock_webrick and args[:handlers] == @listen_params[:handlers] + }.returns(mock_handler) @server.expects(:class_for_protocol).with(protocol).at_least_once.returns(mock_handler_class) end @server.listen(@listen_params) diff --git a/spec/unit/network/http/webrick/rest.rb b/spec/unit/network/http/webrick/rest.rb new file mode 100644 index 000000000..f17f89a15 --- /dev/null +++ b/spec/unit/network/http/webrick/rest.rb @@ -0,0 +1,46 @@ +#!/usr/bin/env ruby +# +# Created by Rick Bradley on 2007-10-16. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../../../spec_helper' +require 'puppet/network/http' + +describe Puppet::Network::HTTP::WEBrickREST, "when initializing" do + before do + @mock_webrick = mock('WEBrick server') + @params = { :server => @mock_webrick, :handlers => [ :foo ] } + end + + it "should require access to a WEBrick server" do + Proc.new { Puppet::Network::HTTP::WEBrickREST.new(@params.delete_if {|k,v| :server == k })}.should raise_error(ArgumentError) + end + + it "should require at least one indirection name" do + Proc.new { Puppet::Network::HTTP::WEBrickREST.new(@params.delete_if {|k,v| :handlers == k })}.should raise_error(ArgumentError) + end + + it "should look up the indirection model from the indirection name" do + mock_model = mock('indirected model') + Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(mock_model) + Puppet::Network::HTTP::WEBrickREST.new(@params) + end + + it "should fail if a handler is not indirected" do + Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(nil) + Proc.new { Puppet::Network::HTTP::WEBrickREST.new(@params) }.should raise_error(ArgumentError) + end + + it "should register a listener for each indirection with the provided WEBrick server" +end + +describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do + it "should unpack request information from WEBrick" + it "should unpack parameters from the request for passing to controller methods" + it "should call the controller find method if the request represents a singular HTTP GET" + it "should call the controller search method if the request represents a plural HTTP GET" + it "should call the controller destroy method if the request represents an HTTP DELETE" + it "should call the controller save method if the request represents an HTTP PUT" + it "should serialize the result from the controller method for return back to Mongrel" + it "should serialize a controller expection result for return back to Mongrel" +end diff --git a/spec/unit/network/http/webrick/xmlrpc.rb b/spec/unit/network/http/webrick/xmlrpc.rb new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/spec/unit/network/http/webrick/xmlrpc.rb |
