diff options
author | Sean McGivern <sean@gitlab.com> | 2018-01-03 14:18:13 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-01-04 14:33:12 +0000 |
commit | 528b5eeb761f627bb1972fa8a25a09dc1cea4556 (patch) | |
tree | 4b32a5e10e331b252599fdad40e44996ab5e5421 /spec/lib/gitlab | |
parent | e5a9b9a14d32d890dea20403c977dfd569eb3e17 (diff) | |
download | gitlab-ce-528b5eeb761f627bb1972fa8a25a09dc1cea4556.tar.gz |
Fix error when viewing diffs without blobs41468-error-500-trying-to-view-a-merge-request-json-undefined-method-binary-for-nil-nilclass
Old merge requests can have diffs without corresponding blobs. (This also may be
possible for commit diffs in corrupt repositories.)
We can't use the `&.` operator on the blobs, because the blob objects are never
nil, but `BatchLoader` instances that delegate to `Blob`. We can't use
`Object#try`, because `Blob` doesn't inherit from `Object`.
`BatchLoader` provides a `__sync` method that returns the delegated object, but
using `itself` also works because it's forwarded, and will work for
non-`BatchLoader` instances too. So the simplest solution is to just use that
with the `&.` operator.
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/diff/file_spec.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb index ff9acfd08b9..9204ea37963 100644 --- a/spec/lib/gitlab/diff/file_spec.rb +++ b/spec/lib/gitlab/diff/file_spec.rb @@ -431,4 +431,29 @@ describe Gitlab::Diff::File do end end end + + context 'when neither blob exists' do + let(:blank_diff_refs) { Gitlab::Diff::DiffRefs.new(base_sha: Gitlab::Git::BLANK_SHA, head_sha: Gitlab::Git::BLANK_SHA) } + let(:diff_file) { described_class.new(diff, diff_refs: blank_diff_refs, repository: project.repository) } + + describe '#blob' do + it 'returns a concrete nil so it can be used in boolean expressions' do + actual = diff_file.blob && true + + expect(actual).to be_nil + end + end + + describe '#binary?' do + it 'returns false' do + expect(diff_file).not_to be_binary + end + end + + describe '#size' do + it 'returns zero' do + expect(diff_file.size).to be_zero + end + end + end end |