From f8649bc54eefe175748426a79f2ce6dc82016c1b Mon Sep 17 00:00:00 2001 From: blackhedd Date: Sun, 23 Apr 2006 01:17:49 +0000 Subject: [PATCH] Changed LDAP#search to return T/F instead of numeric LDAP code, and adjusted the tests accordingly. --- lib/net/ldap.rb | 11 +++++------ tests/testldap.rb | 12 +++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/net/ldap.rb b/lib/net/ldap.rb index 5ff968f..2e2f21c 100644 --- a/lib/net/ldap.rb +++ b/lib/net/ldap.rb @@ -199,22 +199,21 @@ module Net # def search args if @open_connection - result_code = @open_connection.search( args ) {|values| + @result = @open_connection.search( args ) {|values| block_given? and yield( values ) } - result_code else - result_code = 0 + @result = 0 conn = Connection.new( :host => @host, :port => @port ) - if (result_code = conn.bind( args[:auth] || @auth )) == 0 - result_code = conn.search( args ) {|values| + if (@result = conn.bind( args[:auth] || @auth )) == 0 + @result = conn.search( args ) {|values| block_given? and yield( values ) } end conn.close - result_code end + @result == 0 end # diff --git a/tests/testldap.rb b/tests/testldap.rb index e615005..a401476 100644 --- a/tests/testldap.rb +++ b/tests/testldap.rb @@ -88,10 +88,12 @@ class TestLdapClient < Test::Unit::TestCase ldap = Net::LDAP.new :host => @host, :port => @port, :auth => @auth search = {:base => "dc=smalldomain,dc=com"} - assert_equal( 32, ldap.search( search )) + assert_equal( false, ldap.search( search )) + assert_equal( 32, ldap.get_operation_result.code ) search = {:base => "dc=bayshorenetworks,dc=com"} - assert_equal( 0, ldap.search( search )) + assert_equal( true, ldap.search( search )) + assert_equal( 0, ldap.get_operation_result.code ) ldap.search( search ) {|res| assert_equal( res, @ldif ) @@ -118,7 +120,7 @@ class TestLdapClient < Test::Unit::TestCase } } - assert_equal( 0, ldap.search( search )) + assert_equal( true, ldap.search( search )) ldap.search( search ) {|res| res_keys = res.keys.sort ldif_keys = ldif.keys.sort @@ -164,7 +166,7 @@ class TestLdapClient < Test::Unit::TestCase ldap.open {|ldap| 10.times { rc = ldap.search( :base => "dc=bayshorenetworks,dc=com" ) - assert_equal( 0, rc ) + assert_equal( true, rc ) } } end @@ -174,7 +176,7 @@ class TestLdapClient < Test::Unit::TestCase Net::LDAP.open( :host => @host, :port => @port, :auth => @auth ) {|ldap| 10.times { rc = ldap.search( :base => "dc=bayshorenetworks,dc=com" ) - assert_equal( 0, rc ) + assert_equal( true, rc ) } } end