]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
str2bool should return a boolean if called with a boolean
authorJustin Lambert <jlambert@eml.cc>
Mon, 17 Dec 2012 13:22:36 +0000 (06:22 -0700)
committerAdrien Thebo <git@somethingsinistral.net>
Mon, 18 Mar 2013 22:37:36 +0000 (15:37 -0700)
lib/puppet/parser/functions/str2bool.rb
spec/unit/puppet/parser/functions/str2bool_spec.rb

index c320da663a2fc162f2fbcbad52ae3df90b3000f3..9ea6dd51425f28b161f484dc9d1d4ad848b38a35 100644 (file)
@@ -14,6 +14,11 @@ like: 0, f, n, false, no to 'false'.
       "given (#{arguments.size} for 1)") if arguments.size < 1
 
     string = arguments[0]
+    
+    # If string is already Boolean, return it
+    if !!string == string
+      return string
+    end
 
     unless string.is_a?(String)
       raise(Puppet::ParseError, 'str2bool(): Requires either ' +
index 2782bbea85a8345d2c8cb0518458b9ee815c0431..ef6350f25361bef3d31f3b9375dbca254fbba868 100644 (file)
@@ -21,4 +21,11 @@ describe "the str2bool function" do
     result = scope.function_str2bool(["undef"])
     result.should(eq(false))
   end
+  
+  it "should return the boolean it was called with" do
+    result = scope.function_str2bool([true])
+    result.should(eq(true))
+    result = scope.function_str2bool([false])
+    result.should(eq(false))
+  end
 end