summaryrefslogtreecommitdiffstats
path: root/spec/unit/indirector/rest.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/indirector/rest.rb')
-rwxr-xr-xspec/unit/indirector/rest.rb65
1 files changed, 22 insertions, 43 deletions
diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb
index 361412a54..9305a7109 100755
--- a/spec/unit/indirector/rest.rb
+++ b/spec/unit/indirector/rest.rb
@@ -43,6 +43,11 @@ describe Puppet::Indirector::REST do
@response.stubs(:[]).with('content-type').returns "text/plain"
@searcher = @rest_class.new
+ @searcher.stubs(:model).returns @model
+ end
+
+ it "should include the Http Handler module" do
+ Puppet::Indirector::REST.ancestors.should be_include(Puppet::Network::HTTP::Handler)
end
it "should have a method for specifying what setting a subclass should use to retrieve its server" do
@@ -152,7 +157,7 @@ describe Puppet::Indirector::REST do
@searcher.stubs(:network).returns(@connection) # neuter the network connection
# Use a key with spaces, so we can test escaping
- @request = stub 'request', :escaped_key => 'foo', :query_string => ""
+ @request = Puppet::Indirector::Request.new(:foo, :find, "foo bar")
end
it "should call the GET http method on a network connection" do
@@ -168,15 +173,9 @@ describe Puppet::Indirector::REST do
@searcher.find(@request).should == 'myobject'
end
- it "should use the environment, indirection name, and escaped request key to create the path" do
- should_path = "/%s/%s/%s" % [Puppet::Node::Environment.new, @indirection.name.to_s, "foo"]
- @connection.expects(:get).with { |path, args| path == should_path }.returns(@response)
- @searcher.find(@request)
- end
-
- it "should include the query string" do
- @request.expects(:query_string).with().returns "?my_string"
- @connection.expects(:get).with { |path, args| path.include?("?my_string") }.returns(@response)
+ it "should use the URI generated by the Handler module" do
+ @searcher.expects(:indirection2uri).with(@request).returns "/my/uri"
+ @connection.expects(:get).with { |path, args| path == "/my/uri" }.returns(@response)
@searcher.find(@request)
end
@@ -205,7 +204,7 @@ describe Puppet::Indirector::REST do
@model.stubs(:convert_from_multiple)
- @request = stub 'request', :escaped_key => 'foo', :query_string => "", :key => "bar"
+ @request = Puppet::Indirector::Request.new(:foo, :search, "foo bar")
end
it "should call the GET http method on a network connection" do
@@ -221,22 +220,9 @@ describe Puppet::Indirector::REST do
@searcher.search(@request).should == 'myobject'
end
- it "should use the environment and the plural indirection name as the path if there is no request key" do
- should_path = "/%s/%ss" % [Puppet::Node::Environment.new, @indirection.name.to_s]
- @request.stubs(:key).returns nil
- @connection.expects(:get).with { |path, args| path == should_path }.returns(@response)
- @searcher.search(@request)
- end
-
- it "should use the envrironment, the plural indirection name, and the escaped request key to create the path if the request key is set" do
- should_path = "/%s/%ss/%s" % [Puppet::Node::Environment.new, @indirection.name.to_s, "foo"]
- @connection.expects(:get).with { |path, args| path == should_path }.returns(@response)
- @searcher.search(@request)
- end
-
- it "should include the query string" do
- @request.expects(:query_string).with().returns "?my_string"
- @connection.expects(:get).with { |path, args| path.include?("?my_string") }.returns(@response)
+ it "should use the URI generated by the Handler module" do
+ @searcher.expects(:indirection2uri).with(@request).returns "/mys/uri"
+ @connection.expects(:get).with { |path, args| path == "/mys/uri" }.returns(@response)
@searcher.search(@request)
end
@@ -264,7 +250,7 @@ describe Puppet::Indirector::REST do
@connection = stub('mock http connection', :delete => @response)
@searcher.stubs(:network).returns(@connection) # neuter the network connection
- @request = stub 'request', :escaped_key => 'foo', :query_string => "", :options => {}
+ @request = Puppet::Indirector::Request.new(:foo, :destroy, "foo bar")
end
it "should call the DELETE http method on a network connection" do
@@ -286,14 +272,13 @@ describe Puppet::Indirector::REST do
@searcher.destroy(@request).should == 'myobject'
end
- it "should use the environment, the indirection name, and the escaped request key to create the path" do
- should_path = "/%s/%s/%s" % [Puppet::Node::Environment.new, @indirection.name.to_s, "foo"]
- @connection.expects(:delete).with { |path, args| path == should_path }.returns(@response)
+ it "should use the URI generated by the Handler module" do
+ @searcher.expects(:indirection2uri).with(@request).returns "/my/uri"
+ @connection.expects(:delete).with { |path, args| path == "/my/uri" }.returns(@response)
@searcher.destroy(@request)
end
it "should not include the query string" do
- @request.expects(:query_string).never
@connection.stubs(:delete).returns @response
@searcher.destroy(@request)
end
@@ -322,7 +307,8 @@ describe Puppet::Indirector::REST do
@searcher.stubs(:network).returns(@connection) # neuter the network connection
@instance = stub 'instance', :render => "mydata"
- @request = stub 'request', :instance => @instance, :query_string => "", :options => {}
+ @request = Puppet::Indirector::Request.new(:foo, :save, "foo bar")
+ @request.instance = @instance
end
it "should call the PUT http method on a network connection" do
@@ -337,16 +323,9 @@ describe Puppet::Indirector::REST do
lambda { @searcher.save(@request) }.should raise_error(ArgumentError)
end
- it "should use the environment and the indirection name as the path for the request" do
- path = "/%s/%s/" % [Puppet::Node::Environment.new, @indirection.name]
- @connection.expects(:put).with { |path, data, args| path == path }.returns @response
-
- @searcher.save(@request)
- end
-
- it "should not include the query string" do
- @request.expects(:query_string).never
- @connection.stubs(:put).returns @response
+ it "should use the URI generated by the Handler module" do
+ @searcher.expects(:indirection2uri).with(@request).returns "/my/uri"
+ @connection.expects(:put).with { |path, args| path == "/my/uri" }.returns(@response)
@searcher.save(@request)
end