Skip to content

Commit

Permalink
search should return result set if :return_result is unspecified (nil).
Browse files Browse the repository at this point in the history
Corrects incorrect behaviour introduced in a4819e5
  • Loading branch information
danabr committed Oct 7, 2011
1 parent 5344d73 commit 2a74577
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/net/ldap.rb
Expand Up @@ -619,7 +619,8 @@ def search(args = {})
end

args[:base] ||= @base
result_set = args[:return_result] == false ? nil : []
return_result_set = args[:return_result] != false
result_set = return_result_set ? [] : nil

if @open_connection
@result = @open_connection.search(args) { |entry|
Expand All @@ -642,7 +643,7 @@ def search(args = {})
end
end

if args[:return_result]
if return_result_set
@result == 0 ? result_set : nil
else
@result == 0
Expand Down
11 changes: 9 additions & 2 deletions spec/unit/ldap/search_spec.rb
Expand Up @@ -13,17 +13,24 @@ def search(args)
@connection.instance_variable_set(:@open_connection, FakeConnection.new)
end

context "when returning result set" do
context "when :return_result => true" 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
context "when :return_result => false" do
it "should return false upon error" do
success = @connection.search(:return_result => false)
success.should == false
end
end

context "When :return_result is not given" do
it "should return nil upon error" do
result_set = @connection.search
result_set.should be_nil
end
end
end

0 comments on commit 2a74577

Please sign in to comment.