From c9f84f493694599853dc6b91a2dbaa3f303cba9d Mon Sep 17 00:00:00 2001 From: Bertrand Paquet Date: Mon, 23 May 2011 15:00:11 +0200 Subject: [PATCH] Issue #36 Fix problem in previous fixing : crash if find_servers is called with a ServerDefinition object --- lib/capistrano/configuration/servers.rb | 4 ++-- test/configuration/servers_test.rb | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/capistrano/configuration/servers.rb b/lib/capistrano/configuration/servers.rb index 20b066b8..8d92508e 100644 --- a/lib/capistrano/configuration/servers.rb +++ b/lib/capistrano/configuration/servers.rb @@ -39,8 +39,8 @@ module Capistrano # # returns the given hosts, translated to ServerDefinition objects # servers = find_servers :hosts => "jamis@example.host.com" def find_servers(options={}) - return [] if options.key?(:hosts) && (options[:hosts].nil? || options[:hosts] == []) - return [] if options.key?(:roles) && (options[:roles].nil? || options[:roles] == []) + return [] if options.key?(:hosts) && (options[:hosts].nil? || [] == options[:hosts]) + return [] if options.key?(:roles) && (options[:roles].nil? || [] == options[:roles]) hosts = server_list_from(ENV['HOSTS'] || options[:hosts]) diff --git a/test/configuration/servers_test.rb b/test/configuration/servers_test.rb index 51018878..d89f1ae0 100644 --- a/test/configuration/servers_test.rb +++ b/test/configuration/servers_test.rb @@ -159,11 +159,17 @@ class ConfigurationServersTest < Test::Unit::TestCase def test_find_servers_with_hosts_nil_or_empty assert_equal [], @config.find_servers(:hosts => nil) assert_equal [], @config.find_servers(:hosts => []) + result = @config.find_servers(:hosts => @config.find_servers(:roles => :report)[0]) + assert_equal 1, result.size + result = @config.find_servers(:hosts => "app1") + assert_equal 1, result.size end def test_find_servers_with_rolees_nil_or_empty assert_equal [], @config.find_servers(:roles => nil) assert_equal [], @config.find_servers(:roles => []) + result = @config.find_servers(:roles => :report) + assert_equal 1, result.size end end