Skip to content
Snippets Groups Projects
Commit 9639c058 authored by Lin Jen-Shin's avatar Lin Jen-Shin :two:
Browse files

Make sure #eql? will not raise when type unmatched

Also add a test for #eql?
parent 34bd156b
No related branches found
No related tags found
1 merge request!80376Make sure #eql? will not raise when type unmatched
......@@ -20,8 +20,9 @@ def signature_hex
end
def eql?(other)
other.algorithm_type == algorithm_type &&
other.signature_sha == signature_sha
other.is_a?(self.class) &&
other.algorithm_type == algorithm_type &&
other.signature_sha == signature_sha
end
alias_method :==, :eql?
......
......@@ -31,4 +31,47 @@
it { is_expected.to eq([expected_signature]) }
end
describe '#eql?' do
context 'when the other is also a FindingSignature' do
context 'when algorithm_type and signature_sha are the same' do
let(:other) do
build(
:vulnerabilities_finding_signature,
signature_sha: signature.signature_sha,
algorithm_type: signature.algorithm_type)
end
it 'returns true' do
expect(signature.eql?(other)).to eq(true)
end
end
context 'when algorithm_type is different' do
let(:other) { build(:vulnerabilities_finding_signature, :location) }
it 'returns false' do
expect(signature.eql?(other)).to eq(false)
end
end
context 'when signature_sha is different' do
let(:other) { build(:vulnerabilities_finding_signature) }
before do
other.signature_sha = other.signature_sha.reverse
end
it 'returns false' do
expect(signature.eql?(other)).to eq(false)
end
end
end
context 'when the other is not a FindingSignature' do
it 'returns false' do
expect(signature.eql?('something else')).to eq(false)
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment