File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,16 @@ def to_s
24
24
def inspect
25
25
"#<#{ self } >"
26
26
end
27
+
28
+ def hash
29
+ @value . hash
30
+ end
31
+
32
+ def ==( other )
33
+ other . is_a? ( Sensitive ) &&
34
+ other . hash == hash
35
+ end
36
+ alias eql? ==
27
37
end
28
38
29
39
def self . register_ptype ( loader , ir )
Original file line number Diff line number Diff line change @@ -113,6 +113,24 @@ module Types
113
113
expect ( eval_and_collect_notices ( code ) ) . to eq ( [ 'Sensitive[Integer] != Sensitive[String]' ] )
114
114
end
115
115
116
+ it 'equals another instance with the same value' do
117
+ code = <<-CODE
118
+ $i = Sensitive('secret')
119
+ $o = Sensitive('secret')
120
+ notice($i == $o)
121
+ CODE
122
+ expect ( eval_and_collect_notices ( code ) ) . to eq ( [ 'true' ] )
123
+ end
124
+
125
+ it 'has equal hash keys for same values' do
126
+ code = <<-CODE
127
+ $i = Sensitive('secret')
128
+ $o = Sensitive('secret')
129
+ notice({$i => 1} == {$o => 1})
130
+ CODE
131
+ expect ( eval_and_collect_notices ( code ) ) . to eq ( [ 'true' ] )
132
+ end
133
+
116
134
it 'can be created from another sensitive instance ' do
117
135
code = <<-CODE
118
136
$o = Sensitive("hunter2")
You can’t perform that action at this time.
0 commit comments