Commit b224efe7 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'fj-59547-fix-has-commits' into 'master'

Fix MergeRequest#has_commits? nil comparison

Closes #59547

See merge request gitlab-org/gitlab-ce!26828
parents 0a480e3c 45293f66
...@@ -1343,7 +1343,7 @@ class MergeRequest < ApplicationRecord ...@@ -1343,7 +1343,7 @@ class MergeRequest < ApplicationRecord
end end
def has_commits? def has_commits?
merge_request_diff && commits_count > 0 merge_request_diff && commits_count.to_i > 0
end end
def has_no_commits? def has_no_commits?
......
...@@ -2714,14 +2714,21 @@ describe MergeRequest do ...@@ -2714,14 +2714,21 @@ describe MergeRequest do
end end
describe '#has_commits?' do describe '#has_commits?' do
before do it 'returns true when merge request diff has commits' do
allow(subject.merge_request_diff).to receive(:commits_count) allow(subject.merge_request_diff).to receive(:commits_count)
.and_return(2) .and_return(2)
end
it 'returns true when merge request diff has commits' do
expect(subject.has_commits?).to be_truthy expect(subject.has_commits?).to be_truthy
end end
context 'when commits_count is nil' do
it 'returns false' do
allow(subject.merge_request_diff).to receive(:commits_count)
.and_return(nil)
expect(subject.has_commits?).to be_falsey
end
end
end end
describe '#has_no_commits?' do describe '#has_no_commits?' do
......
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