This allows a separation between the wrapper class
and its internals, which is (at least) necessary for
the CA cert, which might not be found using the
internal name.

Signed-off-by: Luke Kanies <[email protected]>
---
 lib/puppet/indirector/rest.rb                   |    4 +++-
 spec/integration/indirector/certificate/rest.rb |    4 +++-
 spec/integration/indirector/rest.rb             |    1 +
 spec/unit/indirector/rest.rb                    |   14 +++++++++++---
 4 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/lib/puppet/indirector/rest.rb b/lib/puppet/indirector/rest.rb
index e1ee89f..a89e986 100644
--- a/lib/puppet/indirector/rest.rb
+++ b/lib/puppet/indirector/rest.rb
@@ -66,7 +66,9 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus
     end
 
     def find(request)
-        deserialize network(request).get(indirection2uri(request), headers)
+        return nil unless result = 
deserialize(network(request).get(indirection2uri(request), headers))
+        result.name = request.key
+        result
     end
 
     def search(request)
diff --git a/spec/integration/indirector/certificate/rest.rb 
b/spec/integration/indirector/certificate/rest.rb
index 3ebd1e5..b8fd211 100755
--- a/spec/integration/indirector/certificate/rest.rb
+++ b/spec/integration/indirector/certificate/rest.rb
@@ -64,6 +64,8 @@ describe "Certificate REST Terminus" do
 
         # There's no good '==' method on certs.
         result.content.to_s.should == @host.certificate.content.to_s
-        result.name.should == @host.certificate.name
+
+        # Make sure the name gets changed as appropriate.
+        result.name.should == "bar"
     end
 end
diff --git a/spec/integration/indirector/rest.rb 
b/spec/integration/indirector/rest.rb
index 077a74f..287387e 100755
--- a/spec/integration/indirector/rest.rb
+++ b/spec/integration/indirector/rest.rb
@@ -11,6 +11,7 @@ class Puppet::TestIndirectedFoo
     indirects :test_indirected_foo, :terminus_setting => 
:test_indirected_foo_terminus
 
     attr_reader :value
+    attr_accessor :name
 
     def initialize(value = 0)
         @value = value
diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb
index d98e6f5..d12e3c6 100755
--- a/spec/unit/indirector/rest.rb
+++ b/spec/unit/indirector/rest.rb
@@ -29,7 +29,7 @@ describe Puppet::Indirector::REST do
     before do
         Puppet::Indirector::Terminus.stubs(:register_terminus_class)
         @model = stub('model', :supported_formats => %w{}, :convert_from => 
nil)
-        @instance = stub('model instance')
+        @instance = stub('model instance', :name= => nil)
         @indirection = stub('indirection', :name => :mystuff, 
:register_terminus_type => nil, :model => @model)
         Puppet::Indirector::Indirection.stubs(:instance).returns(@indirection)
 
@@ -201,9 +201,11 @@ describe Puppet::Indirector::REST do
 
         it "should deserialize and return the http response" do
             @connection.expects(:get).returns @response
-            @searcher.expects(:deserialize).with(@response).returns "myobject"
 
-            @searcher.find(@request).should == 'myobject'
+            instance = stub 'object', :name= => nil
+            @searcher.expects(:deserialize).with(@response).returns instance
+
+            @searcher.find(@request).should == instance
         end
 
         it "should use the URI generated by the Handler module" do
@@ -224,6 +226,12 @@ describe Puppet::Indirector::REST do
             @searcher.find(@request).should equal(@instance)
         end
 
+        it "should set the name of the resulting instance to the asked-for 
name" do
+            @searcher.expects(:deserialize).with(@response).returns @instance
+            @instance.expects(:name=).with "foo bar"
+            @searcher.find(@request)
+        end
+
         it "should generate an error when result data deserializes fails" do
             @searcher.expects(:deserialize).raises(ArgumentError)
             lambda { @searcher.find(@request) }.should 
raise_error(ArgumentError)
-- 
1.6.1


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to