From 64d9f28820c90f1fb2b01f6d0da84d4c8f4c88a8 Mon Sep 17 00:00:00 2001 From: Rufus Post Date: Mon, 11 Jan 2016 14:24:48 +1100 Subject: [PATCH] fix deprecated hash methods --- .rubocop_todo.yml | 9 --------- lib/net/snmp.rb | 2 +- test/test_ldap_connection.rb | 18 +++++++++--------- test/test_ldif.rb | 12 ++++++------ test/test_search.rb | 4 ++-- 5 files changed, 18 insertions(+), 27 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4c6c68d2..3007d218 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -206,15 +206,6 @@ Style/ConstantName: - 'test/test_ldif.rb' - 'testserver/ldapserver.rb' -# Offense count: 18 -# Cop supports --auto-correct. -Style/DeprecatedHashMethods: - Exclude: - - 'lib/net/snmp.rb' - - 'test/test_ldap_connection.rb' - - 'test/test_ldif.rb' - - 'test/test_search.rb' - # Offense count: 21 # Configuration parameters: Exclude. Style/Documentation: diff --git a/lib/net/snmp.rb b/lib/net/snmp.rb index fe7a2899..8767e399 100644 --- a/lib/net/snmp.rb +++ b/lib/net/snmp.rb @@ -191,7 +191,7 @@ def pdu_type= t end def error_status= es - unless ErrorStatusCodes.has_key?(es) + unless ErrorStatusCodes.key?(es) raise Error.new("unknown error-status: #{es}") end @error_status = es diff --git a/test/test_ldap_connection.rb b/test/test_ldap_connection.rb index 51e30c3f..d6f75906 100644 --- a/test/test_ldap_connection.rb +++ b/test/test_ldap_connection.rb @@ -399,8 +399,8 @@ def test_write_net_ldap_connection_event # a write event payload, result = events.pop - assert payload.has_key?(:result) - assert payload.has_key?(:content_length) + assert payload.key?(:result) + assert payload.key?(:content_length) end def test_read_net_ldap_connection_event @@ -416,7 +416,7 @@ def test_read_net_ldap_connection_event # a read event payload, result = events.pop - assert payload.has_key?(:result) + assert payload.key?(:result) assert_equal read_result, result end @@ -433,9 +433,9 @@ def test_parse_pdu_net_ldap_connection_event # a parse_pdu event payload, result = events.pop - assert payload.has_key?(:pdu) - assert payload.has_key?(:app_tag) - assert payload.has_key?(:message_id) + assert payload.key?(:pdu) + assert payload.key?(:app_tag) + assert payload.key?(:message_id) assert_equal Net::LDAP::PDU::BindResult, payload[:app_tag] assert_equal 1, payload[:message_id] pdu = payload[:pdu] @@ -455,7 +455,7 @@ def test_bind_net_ldap_connection_event # a read event payload, result = events.pop - assert payload.has_key?(:result) + assert payload.key?(:result) assert result.success?, "should be success" end @@ -482,8 +482,8 @@ def test_search_net_ldap_connection_event # a search event payload, result = events.pop - assert payload.has_key?(:result) - assert payload.has_key?(:filter) + assert payload.key?(:result) + assert payload.key?(:filter) assert_equal "(uid=user1)", payload[:filter].to_s assert result diff --git a/test/test_ldif.rb b/test/test_ldif.rb index 8181671c..b86eb2fb 100644 --- a/test/test_ldif.rb +++ b/test/test_ldif.rb @@ -38,31 +38,31 @@ def test_ldif_with_password def test_ldif_with_continuation_lines ds = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: abcdefg\r\n hijklmn\r\n\r\n")) - assert_equal(true, ds.has_key?("abcdefghijklmn")) + assert_equal(true, ds.key?("abcdefghijklmn")) end def test_ldif_with_continuation_lines_and_extra_whitespace ds1 = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: abcdefg\r\n hijklmn\r\n\r\n")) - assert_equal(true, ds1.has_key?("abcdefg hijklmn")) + assert_equal(true, ds1.key?("abcdefg hijklmn")) ds2 = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: abcdefg\r\n hij klmn\r\n\r\n")) - assert_equal(true, ds2.has_key?("abcdefghij klmn")) + assert_equal(true, ds2.key?("abcdefghij klmn")) end def test_ldif_tab_is_not_continuation ds = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: key\r\n\tnotcontinued\r\n\r\n")) - assert_equal(true, ds.has_key?("key")) + assert_equal(true, ds.key?("key")) end def test_ldif_with_base64_dn str = "dn:: Q049QmFzZTY0IGRuIHRlc3QsT1U9VGVzdCxPVT1Vbml0cyxEQz1leGFtcGxlLERDPWNvbQ==\r\n\r\n" ds = Net::LDAP::Dataset::read_ldif(StringIO.new(str)) - assert_equal(true, ds.has_key?("CN=Base64 dn test,OU=Test,OU=Units,DC=example,DC=com")) + assert_equal(true, ds.key?("CN=Base64 dn test,OU=Test,OU=Units,DC=example,DC=com")) end def test_ldif_with_base64_dn_and_continuation_lines str = "dn:: Q049QmFzZTY0IGRuIHRlc3Qgd2l0aCBjb250aW51YXRpb24gbGluZSxPVT1UZXN0LE9VPVVua\r\n XRzLERDPWV4YW1wbGUsREM9Y29t\r\n\r\n" ds = Net::LDAP::Dataset::read_ldif(StringIO.new(str)) - assert_equal(true, ds.has_key?("CN=Base64 dn test with continuation line,OU=Test,OU=Units,DC=example,DC=com")) + assert_equal(true, ds.key?("CN=Base64 dn test with continuation line,OU=Test,OU=Units,DC=example,DC=com")) end # TODO, INADEQUATE. We need some more tests diff --git a/test/test_search.rb b/test/test_search.rb index e349d0b8..c577a6a2 100644 --- a/test/test_search.rb +++ b/test/test_search.rb @@ -32,8 +32,8 @@ def test_instrumentation_publishes_event @connection.search(:filter => "test") payload, result = events.pop - assert payload.has_key?(:result) - assert payload.has_key?(:filter) + assert payload.key?(:result) + assert payload.key?(:filter) assert_equal "test", payload[:filter] end end