summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-06-19 17:51:24 -0700
committerelijah <elijah@riseup.net>2013-06-19 17:51:24 -0700
commit23aa42d957294b025a367c543cd99f137c48e289 (patch)
treedba6247f616c72cf9b737d7a47b837498449b685
parent5675bd54cf7dc11a234bb305c64c801c4eeaea62 (diff)
fixed utf8 bug when locale not set, and improved testing for ruby 1.8.
-rw-r--r--lib/leap_cli.rb2
-rw-r--r--lib/leap_cli/config/manager.rb23
-rw-r--r--lib/leap_cli/config/object.rb4
-rw-r--r--lib/leap_cli/version.rb2
-rw-r--r--test/test_helper.rb13
-rw-r--r--test/unit/command_line_test.rb12
6 files changed, 42 insertions, 14 deletions
diff --git a/lib/leap_cli.rb b/lib/leap_cli.rb
index 259c00f..2f9ffec 100644
--- a/lib/leap_cli.rb
+++ b/lib/leap_cli.rb
@@ -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'
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb
index d2bc1f3..92cf190 100644
--- a/lib/leap_cli/config/manager.rb
+++ b/lib/leap_cli/config/manager.rb
@@ -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
diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb
index b88c7b4..1edef3f 100644
--- a/lib/leap_cli/config/object.rb
+++ b/lib/leap_cli/config/object.rb
@@ -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'
diff --git a/lib/leap_cli/version.rb b/lib/leap_cli/version.rb
index bbec03a..00df109 100644
--- a/lib/leap_cli/version.rb
+++ b/lib/leap_cli/version.rb
@@ -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']
diff --git a/test/test_helper.rb b/test/test_helper.rb
index c813ead..45deec9 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -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 = ""
diff --git a/test/unit/command_line_test.rb b/test/unit/command_line_test.rb
index 3493600..4f8333a 100644
--- a/test/unit/command_line_test.rb
+++ b/test/unit/command_line_test.rb
@@ -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