Added support for adding "_search" to the end of any indirection to
'pluralize' it, and added tests to check this functionality and to test
hidden side effect of plurality method unpluralizing indirections.

Paired-With:Paul Berry <p...@puppetlabs.com>
Signed-off-by: Max Martin <m...@puppetlabs.com>
---
 lib/puppet/network/http/api/v1.rb     |    4 ++--
 spec/unit/network/http/api/v1_spec.rb |   12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/puppet/network/http/api/v1.rb 
b/lib/puppet/network/http/api/v1.rb
index 0a04a46..9e51aae 100644
--- a/lib/puppet/network/http/api/v1.rb
+++ b/lib/puppet/network/http/api/v1.rb
@@ -63,9 +63,9 @@ module Puppet::Network::HTTP::API::V1
     return :singular if indirection == "status"
     return :plural if indirection == "inventory"
 
-    result = (indirection =~ /s$/) ? :plural : :singular
+    result = (indirection =~ /s$|_search$/) ? :plural : :singular
 
-    indirection.sub!(/s$/, '') if result
+    indirection.sub!(/s$|_search$|es$/, '')
 
     result
   end
diff --git a/spec/unit/network/http/api/v1_spec.rb 
b/spec/unit/network/http/api/v1_spec.rb
index d47fc8d..e734831 100644
--- a/spec/unit/network/http/api/v1_spec.rb
+++ b/spec/unit/network/http/api/v1_spec.rb
@@ -88,6 +88,18 @@ describe Puppet::Network::HTTP::API::V1 do
       @tester.uri2indirection("GET", "/env/inventory/search", 
{}).method.should == :search
     end
 
+    it "should choose 'search' as the indirection method if the http method is 
a GET and the indirection name is facts_search" do
+      @tester.uri2indirection("GET", "/env/facts_search/bar", 
{}).method.should == :search
+    end
+
+    it "should change indirection name to 'facts' if the http method is a GET 
and the indirection name is facts_search" do
+      @tester.uri2indirection("GET", "/env/facts_search/bar", 
{}).indirection_name.should == :facts
+    end
+
+    it "should change indirection name to 'status' if the http method is a GEt 
and the indirection name is statuses" do
+      @tester.uri2indirection("GET", "/env/statuses/bar", 
{}).indirection_name.should == :status
+    end
+
     it "should choose 'delete' as the indirection method if the http method is 
a DELETE and the indirection name is singular" do
       @tester.uri2indirection("DELETE", "/env/foo/bar", {}).method.should == 
:destroy
     end
-- 
1.7.4

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

Reply via email to