Merge pull request #23 from danabr/correct_return_value_from_search
Correct return value from search
This commit is contained in:
commit
5344d73543
2 changed files with 35 additions and 2 deletions
|
@ -619,7 +619,7 @@ class Net::LDAP
|
||||||
end
|
end
|
||||||
|
|
||||||
args[:base] ||= @base
|
args[:base] ||= @base
|
||||||
result_set = (args and args[:return_result] == false) ? nil : []
|
result_set = args[:return_result] == false ? nil : []
|
||||||
|
|
||||||
if @open_connection
|
if @open_connection
|
||||||
@result = @open_connection.search(args) { |entry|
|
@result = @open_connection.search(args) { |entry|
|
||||||
|
@ -642,7 +642,11 @@ class Net::LDAP
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
result_set || @result == 0
|
if args[:return_result]
|
||||||
|
@result == 0 ? result_set : nil
|
||||||
|
else
|
||||||
|
@result == 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# #bind connects to an LDAP server and requests authentication based on
|
# #bind connects to an LDAP server and requests authentication based on
|
||||||
|
|
29
spec/unit/ldap/search_spec.rb
Normal file
29
spec/unit/ldap/search_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# -*- ruby encoding: utf-8 -*-
|
||||||
|
|
||||||
|
describe Net::LDAP, "search method" do
|
||||||
|
class FakeConnection
|
||||||
|
def search(args)
|
||||||
|
error_code = 1
|
||||||
|
return error_code
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
@connection = Net::LDAP.new
|
||||||
|
@connection.instance_variable_set(:@open_connection, FakeConnection.new)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when returning result set" do
|
||||||
|
it "should return nil upon error" do
|
||||||
|
result_set = @connection.search(:return_result => true)
|
||||||
|
result_set.should be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when returning boolean" do
|
||||||
|
it "should return false upon error" do
|
||||||
|
success = @connection.search(:return_result => false)
|
||||||
|
success.should == false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue