summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-07-29 19:11:58 -0500
committerLuke Kanies <luke@madstop.com>2008-07-29 19:11:58 -0500
commit43a6911f656178efb5c2236c8b890127ab0880d3 (patch)
treebef79d0f47cec0b3e208399d43e7f3a7a357a410 /spec/unit
parent1064b5bdcd207efc20ae4ed0fd509364402964f9 (diff)
Searching again works over REST, including full content-type translation.
The format management is a bit clunky right now, though, so I need to fix how they're managed. Some of these tests fail, but 99% of the remaining work is in other classes so I wanted this as a discrete commit. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/indirector/rest.rb24
-rwxr-xr-xspec/unit/network/http/handler.rb9
2 files changed, 22 insertions, 11 deletions
diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb
index 8d88ca7bb..801e8888e 100755
--- a/spec/unit/indirector/rest.rb
+++ b/spec/unit/indirector/rest.rb
@@ -71,7 +71,18 @@ describe Puppet::Indirector::REST do
response.stubs(:body).returns "mydata"
response.stubs(:code).returns "200"
- @searcher.deserialize(response)
+ @searcher.deserialize(response).should == "myobject"
+ end
+
+ it "should convert and return multiple instances if the return code is in the 200s and 'multiple' is specified" do
+ @model.expects(:convert_from_multiple).with("myformat", "mydata").returns "myobjects"
+
+ response = mock 'response'
+ response.stubs(:[]).with("content-type").returns "myformat"
+ response.stubs(:body).returns "mydata"
+ response.stubs(:code).returns "200"
+
+ @searcher.deserialize(response, true).should == "myobjects"
end
end
@@ -138,6 +149,8 @@ describe Puppet::Indirector::REST do
@connection = stub('mock http connection', :get => @response)
@searcher.stubs(:network).returns(@connection) # neuter the network connection
+ @model.stubs(:convert_from_multiple)
+
@request = stub 'request', :key => 'foo'
end
@@ -147,9 +160,9 @@ describe Puppet::Indirector::REST do
@searcher.search(@request)
end
- it "should deserialize and return the http response" do
+ it "should deserialize as multiple instances and return the http response" do
@connection.expects(:get).returns @response
- @searcher.expects(:deserialize).with(@response).returns "myobject"
+ @searcher.expects(:deserialize).with(@response, true).returns "myobject"
@searcher.search(@request).should == 'myobject'
end
@@ -174,11 +187,6 @@ describe Puppet::Indirector::REST do
@searcher.search(@request)
end
- it "should deserialize and return the network response" do
- @searcher.expects(:deserialize).with(@response).returns @instance
- @searcher.search(@request).should equal(@instance)
- end
-
it "should generate an error when result data deserializes fails" do
@searcher.expects(:deserialize).raises(ArgumentError)
lambda { @searcher.search(@request) }.should raise_error(ArgumentError)
diff --git a/spec/unit/network/http/handler.rb b/spec/unit/network/http/handler.rb
index 0f60b9b10..1ed816d97 100755
--- a/spec/unit/network/http/handler.rb
+++ b/spec/unit/network/http/handler.rb
@@ -296,6 +296,7 @@ describe Puppet::Network::HTTP::Handler do
@result2 = mock 'results'
@result = [@result1, @result2]
+ @model_class.stubs(:render_multiple).returns "my rendered instances"
@model_class.stubs(:search).returns(@result)
end
@@ -320,11 +321,13 @@ describe Puppet::Network::HTTP::Handler do
end
it "should return a list of serialized objects when a model search call succeeds" do
- pending "I have not figured out how to do this yet"
- @result1.expects(:render).returns "result1"
- @result2.expects(:render).returns "result2"
+ @handler.expects(:accept_header).with(@request).returns "one,two"
@model_class.stubs(:search).returns(@result)
+
+ @model_class.expects(:render_multiple).with("one", @result).returns "my rendered instances"
+
+ @handler.expects(:set_response).with { |response, data| data == "my rendered instances" }
@handler.do_search(@request, @response)
end
end