summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/network/http/handler.rb4
-rw-r--r--lib/puppet/network/http/webrick/rest.rb2
-rw-r--r--spec/unit/network/http/mongrel/rest.rb21
-rw-r--r--spec/unit/network/http/webrick/rest.rb57
4 files changed, 69 insertions, 15 deletions
diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb
index 4365fffca..9b21946c7 100644
--- a/lib/puppet/network/http/handler.rb
+++ b/lib/puppet/network/http/handler.rb
@@ -31,14 +31,14 @@ class Puppet::Network::HTTP::Handler
def do_destroy(request, response)
key = request_key(request) || raise(ArgumentError, "Could not locate lookup key in request path [#{path}]")
args = params(request)
- @model.destroy(key, args)
+ encode_result(request, response, @model.destroy(key, args))
end
def do_save(request, response)
data = body(request)
raise ArgumentError, "No data to save" if !data or data.empty?
args = params(request)
- @model.new.save(args.merge(:data => data))
+ encode_result(request, response, @model.new.save(args.merge(:data => data)))
end
def find_model_for_handler(handler)
diff --git a/lib/puppet/network/http/webrick/rest.rb b/lib/puppet/network/http/webrick/rest.rb
index 1475ed781..d30f9318b 100644
--- a/lib/puppet/network/http/webrick/rest.rb
+++ b/lib/puppet/network/http/webrick/rest.rb
@@ -35,6 +35,6 @@ class Puppet::Network::HTTP::WEBrickREST < Puppet::Network::HTTP::Handler
end
def encode_result(request, response, result)
- result
+ response.status = 200
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 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"