Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/net/ldap/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ def attribute_names
@myhash.keys
end

##
# Creates a duplicate of the internal Hash containing the attributes
# of the entry.
def to_h
@myhash.dup
end

##
# Accesses each of the attributes present in the Entry.
#
Expand Down
15 changes: 15 additions & 0 deletions test/test_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ def test_case_insensitive_attribute_names
assert_equal ['Jensen'], @entry['Sn']
assert_equal ['Jensen'], @entry['SN']
end

def test_to_h
@entry['sn'] = 'Jensen'
expected = {
dn: ['cn=Barbara,o=corp'],
sn: ['Jensen'],
}
duplicate = @entry.to_h
assert_equal expected, duplicate

# check that changing the duplicate
# does not affect the internal state
duplicate.delete(:sn)
assert_not_equal duplicate, @entry.to_h
end
end

class TestEntryLDIF < Test::Unit::TestCase
Expand Down