Signed-off-by: Luke Kanies <[email protected]>
---
 lib/puppet/indirector/request.rb |   14 ++++++++++----
 spec/unit/indirector/request.rb  |   17 +++++++++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb
index 3f7d1c5..5c577a0 100644
--- a/lib/puppet/indirector/request.rb
+++ b/lib/puppet/indirector/request.rb
@@ -36,10 +36,6 @@ class Puppet::Indirector::Request
         URI.escape(key)
     end
 
-    def indirection_name=(name)
-        @indirection_name = name.to_sym
-    end
-
     # LAK:NOTE This is a messy interface to the cache, and it's only
     # used by the Configurer class.  I decided it was better to implement
     # it now and refactor later, when we have a better design, than
@@ -91,6 +87,16 @@ class Puppet::Indirector::Request
         Puppet::Indirector::Indirection.instance(indirection_name)
     end
 
+    def indirection_name=(name)
+        @indirection_name = name.to_sym
+    end
+
+
+    def model
+        raise ArgumentError, "Could not find indirection '%s'" % 
indirection_name unless i = indirection
+        i.model
+    end
+
     # Should we allow use of the cached object?
     def use_cache?
         if defined?(@use_cache)
diff --git a/spec/unit/indirector/request.rb b/spec/unit/indirector/request.rb
index 241f5f9..e2a871a 100755
--- a/spec/unit/indirector/request.rb
+++ b/spec/unit/indirector/request.rb
@@ -158,6 +158,23 @@ describe Puppet::Indirector::Request do
         request.indirection.should equal(ind)
     end
 
+    it "should use its indirection to look up the appropriate model" do
+        ind = mock 'indirection'
+        
Puppet::Indirector::Indirection.expects(:instance).with(:myind).returns ind
+        request = Puppet::Indirector::Request.new(:myind, :method, :key)
+
+        ind.expects(:model).returns "mymodel"
+
+        request.model.should == "mymodel"
+    end
+
+    it "should fail intelligently when asked to find a model but the 
indirection cannot be found" do
+        
Puppet::Indirector::Indirection.expects(:instance).with(:myind).returns nil
+        request = Puppet::Indirector::Request.new(:myind, :method, :key)
+
+        lambda { request.model }.should raise_error(ArgumentError)
+    end
+
     it "should have a method for determining if the request is plural or 
singular" do
         Puppet::Indirector::Request.new(:myind, :method, :key).should 
respond_to(:plural?)
     end
-- 
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