From 40f0e1857ee619250051d7d37f48a5c03424a29f Mon Sep 17 00:00:00 2001 From: Michael Baker Date: Wed, 30 Nov 2011 20:03:02 +0000 Subject: [PATCH] Add success and failure methods. --- lib/net/ldap/pdu.rb | 8 ++++++++ spec/unit/ldap_spec.rb | 16 ++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/net/ldap/pdu.rb b/lib/net/ldap/pdu.rb index 37c3c08..b771fab 100644 --- a/lib/net/ldap/pdu.rb +++ b/lib/net/ldap/pdu.rb @@ -128,6 +128,14 @@ class Net::LDAP::PDU result_code == 0 ? :success : :failure end + def success? + status == :success + end + + def failure? + !success? + end + ## # Return serverSaslCreds, which are only present in BindResponse packets. #-- diff --git a/spec/unit/ldap_spec.rb b/spec/unit/ldap_spec.rb index 0cf91ae..272d4ee 100644 --- a/spec/unit/ldap_spec.rb +++ b/spec/unit/ldap_spec.rb @@ -7,11 +7,11 @@ describe Net::LDAP::Connection do flexmock(TCPSocket). should_receive(:new).and_raise(Errno::ECONNREFUSED) end - + it "should raise LdapError" do lambda { Net::LDAP::Connection.new( - :server => 'test.mocked.com', + :server => 'test.mocked.com', :port => 636) }.should raise_error(Net::LDAP::LdapError) end @@ -21,11 +21,11 @@ describe Net::LDAP::Connection do flexmock(TCPSocket). should_receive(:new).and_raise(SocketError) end - + it "should raise LdapError" do lambda { Net::LDAP::Connection.new( - :server => 'test.mocked.com', + :server => 'test.mocked.com', :port => 636) }.should raise_error(Net::LDAP::LdapError) end @@ -35,11 +35,11 @@ describe Net::LDAP::Connection do flexmock(TCPSocket). should_receive(:new).and_raise(NameError) end - + it "should rethrow the exception" do lambda { Net::LDAP::Connection.new( - :server => 'test.mocked.com', + :server => 'test.mocked.com', :port => 636) }.should raise_error(NameError) end @@ -61,7 +61,7 @@ describe Net::LDAP::Connection do @tcp_socket.should_receive(:read_ber).and_return([2, ber]) result = subject.modify(:dn => "1", :operations => [[:replace, "mail", "something@sothsdkf.com"]]) - result.status.should == :failure + result.should be_failure result.error_message.should == "The provided password value was rejected by a password validator: The provided password did not contain enough characters from the character set 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. The minimum number of characters from that set that must be present in user passwords is 1" end @@ -71,7 +71,7 @@ describe Net::LDAP::Connection do @tcp_socket.should_receive(:read_ber).and_return([2, ber]) result = subject.modify(:dn => "1", :operations => [[:replace, "mail", "something@sothsdkf.com"]]) - result.status.should == :success + result.should be_success result.error_message.should == "" end end