summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-16 13:24:58 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-16 13:24:58 -0500
commit6ab78f62ee589e542fd653a54109c0f5141ea026 (patch)
tree0f601c90b4a73df4da87f3fd2f04acab5515585b /spec
parentb8c877c121f6b376cd44b13cb90d69c41d0fb004 (diff)
downloadpuppet-6ab78f62ee589e542fd653a54109c0f5141ea026.tar.gz
puppet-6ab78f62ee589e542fd653a54109c0f5141ea026.tar.xz
puppet-6ab78f62ee589e542fd653a54109c0f5141ea026.zip
Inlined the controller, eliminating a class. Mongrel+REST has the right bits for request handling prior to the encode/decode/exception-handling bits. Refactored to make the common logic extractable to a base class.
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/network/controller.rb45
-rw-r--r--spec/unit/network/http/mongrel/rest.rb50
-rw-r--r--spec/unit/network/http/webrick/rest.rb11
3 files changed, 54 insertions, 52 deletions
diff --git a/spec/unit/network/controller.rb b/spec/unit/network/controller.rb
deleted file mode 100644
index 9098b6e25..000000000
--- a/spec/unit/network/controller.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Rick Bradley on 2007-10-03.
-# Copyright (c) 2007. All rights reserved.
-
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-require 'puppet/network/controller'
-
-describe Puppet::Network::Controller, "when initializing" do
- it "should require an indirection name" do
- Proc.new { Puppet::Network::Controller.new }.should raise_error(ArgumentError)
- end
-end
-
-describe Puppet::Network::Controller, "after initialization" do
- before do
- @mock_model_class = mock('model class')
- Puppet::Network::Controller.any_instance.stubs(:model_class_from_indirection_name).returns(@mock_model_class)
- @controller = Puppet::Network::Controller.new(:indirection => :foo)
- end
-
- it "should delegate find to the indirection's model class's find" do
- @mock_model_class.expects(:find).returns({:foo => :bar})
- @controller.find.should == { :foo => :bar }
- end
-
- it "should delegate search to the indirection's model class's search" do
- @mock_model_class.expects(:search).returns({:foo => :bar})
- @controller.search.should == { :foo => :bar }
- end
-
- it "should delegate destroy to the indirection's model class's destroy" do
- @mock_model_class.expects(:destroy).returns({:foo => :bar})
- @controller.destroy.should == { :foo => :bar }
- end
-
- it "should delegate save to the indirection's model class's save" do
- data = { :bar => :xyzzy }
- mock_model_instance = mock('model instance')
- @mock_model_class.expects(:new).with(data).returns(mock_model_instance)
- mock_model_instance.expects(:save).returns({:foo => :bar})
- @controller.save(data).should == { :foo => :bar }
- end
-end \ No newline at end of file
diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb
index 49562e866..c45ca8d66 100644
--- a/spec/unit/network/http/mongrel/rest.rb
+++ b/spec/unit/network/http/mongrel/rest.rb
@@ -49,12 +49,52 @@ describe Puppet::Network::HTTP::MongrelREST, "when initializing" do
end
describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
+ before do
+ @mock_request = mock('mongrel http request')
+ @mock_response = mock('mongrel http response')
+ @mock_model_class = mock('indirected model class')
+ Puppet::Indirector::Indirection.stubs(:model).with(:foo).returns(@mock_model_class)
+ @mock_mongrel = mock('mongrel http server')
+ @mock_mongrel.stubs(:register)
+ @handler = Puppet::Network::HTTP::MongrelREST.new(:server => @mock_mongrel, :handler => :foo)
+ end
+
+ it "should call the model find method if the request represents a singular HTTP GET" do
+ @mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'GET', Mongrel::Const::REQUEST_PATH => '/foo'})
+ @mock_model_class.expects(:find)
+ @handler.process(@mock_request, @mock_response)
+ end
+
+ it "should call the model search method if the request represents a plural HTTP GET" do
+ @mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'GET', Mongrel::Const::REQUEST_PATH => '/foos'})
+ @mock_model_class.expects(:search)
+ @handler.process(@mock_request, @mock_response)
+ end
+
+ it "should call the model destroy method if the request represents an HTTP DELETE" do
+ @mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'DELETE', Mongrel::Const::REQUEST_PATH => '/foo'})
+ @mock_model_class.expects(:destroy)
+ @handler.process(@mock_request, @mock_response)
+ end
+
+ it "should call the model save method if the request represents an HTTP PUT" do
+ @mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'PUT', Mongrel::Const::REQUEST_PATH => '/foo'})
+ mock_model_instance = mock('indirected model instance')
+ mock_model_instance.expects(:save)
+ @mock_model_class.expects(:new).returns(mock_model_instance)
+ @handler.process(@mock_request, @mock_response)
+ end
+
+ it "should fail if the HTTP method isn't supported" do
+ @mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'POST', Mongrel::Const::REQUEST_PATH => '/foo'})
+ Proc.new { @handler.process(@mock_request, @mock_response) }.should raise_error(ArgumentError)
+ end
+
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"
+
+ it "should serialize a controller exception result for return back to Mongrel"
end
diff --git a/spec/unit/network/http/webrick/rest.rb b/spec/unit/network/http/webrick/rest.rb
index 70c50bf39..418c97b6f 100644
--- a/spec/unit/network/http/webrick/rest.rb
+++ b/spec/unit/network/http/webrick/rest.rb
@@ -50,11 +50,18 @@ 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"
+
+ it "should serialize the result from the controller method for return back to WEBrick"
+
+ it "should serialize a controller exception result for return back to WEBrick"
end