Commit c6223c94 authored by Mark Chao's avatar Mark Chao

Merge branch...

Merge branch '332621-diffs_metatdata-returning-500-error-nil-can-t-be-coerced-into-integer' into 'master'

Resolve "diffs_metatdata Returning 500 Error - nil can't be coerced into Integer"

See merge request gitlab-org/gitlab!63338
parents 8da3c665 a3cac138
...@@ -9,7 +9,7 @@ class MergeRequestDiffEntity < Grape::Entity ...@@ -9,7 +9,7 @@ class MergeRequestDiffEntity < Grape::Entity
@merge_request_diffs = options[:merge_request_diffs] @merge_request_diffs = options[:merge_request_diffs]
diff = options[:merge_request_diff] diff = options[:merge_request_diff]
next unless diff.present? next unless @merge_request_diffs.include?(diff)
next unless @merge_request_diffs.size > 1 next unless @merge_request_diffs.size > 1
version_index(merge_request_diff) version_index(merge_request_diff)
......
...@@ -11,7 +11,13 @@ RSpec.describe MergeRequestDiffEntity do ...@@ -11,7 +11,13 @@ RSpec.describe MergeRequestDiffEntity do
let(:merge_request_diff) { merge_request_diffs.first } let(:merge_request_diff) { merge_request_diffs.first }
let(:entity) do let(:entity) do
described_class.new(merge_request_diff, request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs) described_class.new(
merge_request_diff,
request: request,
merge_request: merge_request,
merge_request_diff: merge_request_diff,
merge_request_diffs: merge_request_diffs
)
end end
subject { entity.as_json } subject { entity.as_json }
...@@ -26,6 +32,46 @@ RSpec.describe MergeRequestDiffEntity do ...@@ -26,6 +32,46 @@ RSpec.describe MergeRequestDiffEntity do
end end
end end
describe '#version_index' do
shared_examples 'version_index is nil' do
it 'returns nil' do
expect(subject[:version_index]).to be_nil
end
end
context 'when diff is not present' do
let(:entity) do
described_class.new(
merge_request_diff,
request: request,
merge_request: merge_request,
merge_request_diffs: merge_request_diffs
)
end
it_behaves_like 'version_index is nil'
end
context 'when diff is not included in @merge_request_diffs' do
let(:merge_request_diff) { create(:merge_request_diff) }
let(:merge_request_diff_2) { create(:merge_request_diff) }
before do
merge_request_diffs << merge_request_diff_2
end
it_behaves_like 'version_index is nil'
end
context 'when @merge_request_diffs.size <= 1' do
before do
expect(merge_request_diffs.size).to eq(1)
end
it_behaves_like 'version_index is nil'
end
end
describe '#short_commit_sha' do describe '#short_commit_sha' do
it 'returns short sha' do it 'returns short sha' do
expect(subject[:short_commit_sha]).to eq('b83d6e39') expect(subject[:short_commit_sha]).to eq('b83d6e39')
......
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