]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
fixed utf8 bug when locale not set, and improved testing for ruby 1.8.
authorelijah <elijah@riseup.net>
Thu, 20 Jun 2013 00:51:24 +0000 (17:51 -0700)
committerelijah <elijah@riseup.net>
Thu, 20 Jun 2013 00:51:24 +0000 (17:51 -0700)
lib/leap_cli.rb
lib/leap_cli/config/manager.rb
lib/leap_cli/config/object.rb
lib/leap_cli/version.rb
test/test_helper.rb
test/unit/command_line_test.rb

index 259c00f04254cd75fff1f05a544b074f2a9774a6..2f9ffecfdc32c1fc606913dbb5b7382c948f3400 100644 (file)
@@ -1,5 +1,7 @@
 module LeapCli; end
 
+$ruby_version = RUBY_VERSION.split('.').collect{ |i| i.to_i }.extend(Comparable)
+
 require 'leap/platform.rb'
 
 require 'leap_cli/version.rb'
index d2bc1f38d1098004d4025b5f0cfb9a86919b14d5..92cf1903a0a9134d5dbc404fe401fa0c629a26be 100644 (file)
@@ -1,5 +1,9 @@
 require 'json/pure'
 
+if $ruby_version < [1,9]
+  require 'iconv'
+end
+
 module LeapCli
   module Config
 
@@ -218,9 +222,18 @@ module LeapCli
           end
         end
 
+        #
+        # force UTF-8
+        #
+        if $ruby_version >= [1,9]
+          string = buffer.string.force_encoding('utf-8')
+        else
+          string = Iconv.conv("UTF-8//IGNORE", "UTF-8", buffer.string)
+        end
+
         # parse json
         begin
-          hash = JSON.parse(buffer.string, :object_class => Hash, :array_class => Array) || {}
+          hash = JSON.parse(string, :object_class => Hash, :array_class => Array) || {}
         rescue SyntaxError, JSON::ParserError => exc
           log 0, :error, 'in file "%s":' % filename
           log 0, exc.to_s, :indent => 1
@@ -293,11 +306,10 @@ module LeapCli
 
       def remove_disabled_nodes
         @disabled_nodes = Config::ObjectList.new
-        @nodes.select! do |name, node|
-          if node.enabled
-            true
-          else
+        @nodes.each do |name, node|
+          unless node.enabled
             log 2, :skipping, "disabled node #{name}."
+            @nodes.delete(name)
             @disabled_nodes[name] = node
             if node['services']
               node['services'].to_a.each do |node_service|
@@ -309,7 +321,6 @@ module LeapCli
                 @tags[node_tag].node_list.delete(node.name)
               end
             end
-            false
           end
         end
       end
index b88c7b4f1d856f78eab71c8767eb06a47053e3f8..1edef3f0a4630a3e22b3395bbdc6a70188d802dc 100644 (file)
@@ -1,7 +1,9 @@
 require 'erb'
 require 'json/pure'  # pure ruby implementation is required for our sorted trick to work.
 
-$KCODE = 'UTF8' unless RUBY_VERSION > "1.9.0"
+if $ruby_version < [1,9]
+  $KCODE = 'UTF8'
+end
 require 'ya2yaml' # pure ruby yaml
 
 require 'leap_cli/config/macros'
index bbec03ac80a88e6e8d0effb29db8fc1e9eba851b..00df109fc136d87222b4d64631dc8a7b188da761 100644 (file)
@@ -1,6 +1,6 @@
 module LeapCli
   unless defined?(LeapCli::VERSION)
-    VERSION = '1.1.0'
+    VERSION = '1.1.1'
     SUMMARY = 'Command line interface to the LEAP platform'
     DESCRIPTION = 'The command "leap" can be used to manage a bevy of servers running the LEAP platform from the comfort of your own home.'
     LOAD_PATHS = ['lib', 'vendor/certificate_authority/lib', 'vendor/rsync_command/lib']
index c813ead8e9604d74d749e8586d261836b5b8703c..45deec95c0741ff56e925e700fbb1b90afed4f84 100644 (file)
@@ -31,7 +31,7 @@ class MiniTest::Unit::TestCase
   end
 
   def leap_bin(*args)
-    `#{ruby_path} #{base_path}/bin/leap #{args.join ' '}`
+    `cd #{test_provider_path} && #{ruby_path} #{base_path}/bin/leap #{args.join ' '}`
   end
 
   #def test_platform_path
@@ -43,9 +43,14 @@ class MiniTest::Unit::TestCase
   end
 
   def with_multiple_rubies(&block)
-    ['ruby1.8', 'ruby1.9.1'].each do |ruby|
-      self.ruby_path = `which #{ruby}`.strip
-      next unless ruby_path.chars.any?
+    if ENV["RUBY"]
+      ENV["RUBY"].split(',').each do |ruby|
+        self.ruby_path = `which #{ruby}`.strip
+        next unless ruby_path.chars.any?
+        yield
+      end
+    else
+      self.ruby_path = `which ruby`.strip
       yield
     end
     self.ruby_path = ""
index 3493600b9b8d7fd63558ba624f5b5fdafab32def..4f8333a537e19ded1252ed8859596b6d0376ba3f 100644 (file)
@@ -3,10 +3,18 @@ require File.expand_path('../test_helper', __FILE__)
 class CommandLineTest < MiniTest::Unit::TestCase
 
   def test_help
-    #with_multiple_rubies do
+    with_multiple_rubies do
       output = leap_bin('help')
       assert_equal 0, $?, "help should exit 0 -- #{output}"
-    #end
+    end
+  end
+
+  def test_list
+    with_multiple_rubies do
+      output = leap_bin('list')
+      assert_equal 0, $?, "list should exit 0"
+      assert output =~ /ns1   dns/m
+    end
   end
 
 end