Skip to content

Commit a86cc32

Browse files
Merge pull request #286 from thorsteneckel/master
Added method to get a duplicate of the internal Hash
2 parents 87002c3 + 2fe7e50 commit a86cc32

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/net/ldap/entry.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ def attribute_names
133133
@myhash.keys
134134
end
135135

136+
##
137+
# Creates a duplicate of the internal Hash containing the attributes
138+
# of the entry.
139+
def to_h
140+
@myhash.dup
141+
end
142+
136143
##
137144
# Accesses each of the attributes present in the Entry.
138145
#

test/test_entry.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ def test_case_insensitive_attribute_names
3939
assert_equal ['Jensen'], @entry['Sn']
4040
assert_equal ['Jensen'], @entry['SN']
4141
end
42+
43+
def test_to_h
44+
@entry['sn'] = 'Jensen'
45+
expected = {
46+
dn: ['cn=Barbara,o=corp'],
47+
sn: ['Jensen'],
48+
}
49+
duplicate = @entry.to_h
50+
assert_equal expected, duplicate
51+
52+
# check that changing the duplicate
53+
# does not affect the internal state
54+
duplicate.delete(:sn)
55+
assert_not_equal duplicate, @entry.to_h
56+
end
4257
end
4358

4459
class TestEntryLDIF < Test::Unit::TestCase

0 commit comments

Comments
 (0)