summaryrefslogtreecommitdiffstats
path: root/spec/unit/network
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-23 11:12:22 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-23 11:12:22 -0500
commitd28a9041039860beb9e19da267bbad40ecebf8f1 (patch)
tree14eb80238e329bf741d8895d7efe9cd5065a0ec6 /spec/unit/network
parent7def1eaa0e6e559ed70f260bf7b42d8e84d3740b (diff)
REST handlers now properly returning 200 status on success.
Diffstat (limited to 'spec/unit/network')
-rw-r--r--spec/unit/network/http/mongrel/rest.rb21
-rw-r--r--spec/unit/network/http/webrick/rest.rb57
2 files changed, 66 insertions, 12 deletions
diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb
index f5bb867f7..944b0896e 100644
--- a/spec/unit/network/http/mongrel/rest.rb
+++ b/spec/unit/network/http/mongrel/rest.rb
@@ -195,9 +195,26 @@ describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
@handler.process(@mock_request, @mock_response)
end
- it "should generate a 200 response when a model destroy call succeeds"
+ it "should generate a 200 response when a model destroy call succeeds" do
+ @mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'DELETE',
+ Mongrel::Const::REQUEST_PATH => '/foo/key',
+ 'QUERY_STRING' => ''})
+ @mock_model_class.stubs(:destroy)
+ @mock_response.expects(:start).with(200)
+ @handler.process(@mock_request, @mock_response)
+ end
- it "should generate a 200 response when a model save call succeeds"
+ it "should generate a 200 response when a model save call succeeds" do
+ @mock_request.stubs(:params).returns({ Mongrel::Const::REQUEST_METHOD => 'PUT',
+ Mongrel::Const::REQUEST_PATH => '/foo',
+ 'QUERY_STRING' => ''})
+ @mock_request.stubs(:body).returns('this is a fake request body')
+ @mock_model_instance = mock('model instance')
+ @mock_model_instance.stubs(:save)
+ @mock_model_class.stubs(:new).returns(@mock_model_instance)
+ @mock_response.expects(:start).with(200)
+ @handler.process(@mock_request, @mock_response)
+ end
it "should return a serialized object when a model find call succeeds"
diff --git a/spec/unit/network/http/webrick/rest.rb b/spec/unit/network/http/webrick/rest.rb
index bd4bd304c..9d1f5fc6b 100644
--- a/spec/unit/network/http/webrick/rest.rb
+++ b/spec/unit/network/http/webrick/rest.rb
@@ -53,6 +53,7 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@mock_request = mock('webrick http request')
@mock_request.stubs(:query).returns({})
@mock_response = mock('webrick http response')
+ @mock_response.stubs(:status=)
@mock_model_class = mock('indirected model class')
Puppet::Indirector::Indirection.stubs(:model).with(:foo).returns(@mock_model_class)
@mock_webrick = mock('mongrel http server')
@@ -85,9 +86,9 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@mock_request.stubs(:request_method).returns('PUT')
@mock_request.stubs(:path).returns('/foo')
@mock_request.stubs(:body).returns('This is a fake request body')
- mock_model_instance = mock('indirected model instance')
- mock_model_instance.expects(:save).with(:data => 'This is a fake request body')
- @mock_model_class.expects(:new).returns(mock_model_instance)
+ @mock_model_instance = mock('indirected model instance')
+ @mock_model_instance.expects(:save).with(:data => 'This is a fake request body')
+ @mock_model_class.expects(:new).returns(@mock_model_instance)
@handler.service(@mock_request, @mock_response)
end
@@ -166,18 +167,54 @@ describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
@mock_request.stubs(:path).returns('/foo')
@mock_request.stubs(:query).returns(:foo => :baz, :bar => :xyzzy)
@mock_request.stubs(:body).returns('This is a fake request body')
- mock_model_instance = mock('indirected model instance')
- mock_model_instance.expects(:save).with do |args|
+ @mock_model_instance = mock('indirected model instance')
+ @mock_model_instance.expects(:save).with do |args|
args[:data] == 'This is a fake request body' and args[:foo] == :baz and args[:bar] == :xyzzy
end
- @mock_model_class.expects(:new).returns(mock_model_instance)
+ @mock_model_class.expects(:new).returns(@mock_model_instance)
@handler.service(@mock_request, @mock_response)
end
- it "should generate a 200 response when a model find call succeeds"
- it "should generate a 200 response when a model search call succeeds"
- it "should generate a 200 response when a model destroy call succeeds"
- it "should generate a 200 response when a model save call succeeds"
+ it "should generate a 200 response when a model find call succeeds" do
+ @mock_request.stubs(:query).returns(:foo => :baz, :bar => :xyzzy)
+ @mock_request.stubs(:request_method).returns('GET')
+ @mock_request.stubs(:path).returns('/foo/key')
+ @mock_model_class.stubs(:find)
+ @mock_response.expects(:status=).with(200)
+ @handler.process(@mock_request, @mock_response)
+ end
+
+ it "should generate a 200 response when a model search call succeeds" do
+ @mock_request.stubs(:query).returns(:foo => :baz, :bar => :xyzzy)
+ @mock_request.stubs(:request_method).returns('GET')
+ @mock_request.stubs(:path).returns('/foos/key')
+ @mock_model_class.stubs(:search)
+ @mock_response.expects(:status=).with(200)
+ @handler.process(@mock_request, @mock_response)
+ end
+
+ it "should generate a 200 response when a model destroy call succeeds" do
+ @mock_request.stubs(:query).returns(:foo => :baz, :bar => :xyzzy)
+ @mock_request.stubs(:request_method).returns('DELETE')
+ @mock_request.stubs(:path).returns('/foo/key')
+ @mock_model_class.stubs(:destroy)
+ @mock_response.expects(:status=).with(200)
+ @handler.process(@mock_request, @mock_response)
+ end
+
+ it "should generate a 200 response when a model save call succeeds" do
+ @mock_request.stubs(:request_method).returns('PUT')
+ @mock_request.stubs(:path).returns('/foo')
+ @mock_request.stubs(:query).returns(:foo => :baz, :bar => :xyzzy)
+ @mock_request.stubs(:body).returns('This is a fake request body')
+ @mock_model_instance = mock('indirected model instance')
+ @mock_model_class.stubs(:new).returns(@mock_model_instance)
+ @mock_model_instance.stubs(:save)
+ @mock_response.expects(:status=).with(200)
+ @handler.process(@mock_request, @mock_response)
+ end
+
+
it "should return a serialized object when a model find call succeeds"
it "should return a list of serialized object matches when a model search call succeeds"
it "should return a serialized success result when a model destroy call succeeds"