Commit d0a04466 authored by Alex Kalderimis's avatar Alex Kalderimis

Allow shas that are nil to compare to nil shas

Previously, nil == nil was being treated as false. This is both clearly
wrong and more seriously broke the equality contract of `DiffRefs`,
since the same object would not compare equal to itself it any of its
components was nil.

Adds a test for commit.diff_refs equality, the motivating case.
parent a345c54f
......@@ -88,6 +88,7 @@ module Gitlab
end
def shas_eql?(sha1, sha2)
return true if sha1.nil? && sha2.nil?
return false if sha1.nil? || sha2.nil?
return false unless sha1.class == sha2.class
......
......@@ -73,7 +73,8 @@ describe Gitlab::Git do
[sha, short_sha, true],
[sha, sha.reverse, false],
[sha, too_short_sha, false],
[sha, nil, false]
[sha, nil, false],
[nil, nil, true]
]
end
......
......@@ -63,6 +63,20 @@ describe Commit do
end
end
describe '#diff_refs' do
it 'is equal to itself' do
expect(commit.diff_refs).to eq(commit.diff_refs)
end
context 'from a factory' do
let(:commit) { create(:commit) }
it 'is equal to itself' do
expect(commit.diff_refs).to eq(commit.diff_refs)
end
end
end
describe '#author', :request_store do
it 'looks up the author in a case-insensitive way' do
user = create(:user, email: commit.author_email.upcase)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment