Merge branch 'osw-fallback-to-collection-when-no-diff-refs' into 'master'

Render MR page when no persisted diff_refs or diffs size

Closes #49342

See merge request gitlab-org/gitlab-ce!20680
This commit is contained in:
Sean McGivern 2018-07-18 10:24:04 +00:00
commit 89f478545b
4 changed files with 31 additions and 1 deletions

View file

@ -182,7 +182,7 @@ class MergeRequestDiff < ActiveRecord::Base
end
def diffs(diff_options = nil)
if without_files? && comparison = diff_refs.compare_in(project)
if without_files? && comparison = diff_refs&.compare_in(project)
# It should fetch the repository when diffs are cleaned by the system.
# We don't keep these for storage overload purposes.
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/37639

View file

@ -0,0 +1,5 @@
---
title: Render MR page when diffs cannot be fetched from the database or the git repository
merge_request: 20680
author:
type: fixed

View file

@ -53,6 +53,23 @@ describe Projects::MergeRequestsController do
it_behaves_like "loads labels", :show
describe 'as html' do
context 'when diff files were cleaned' do
render_views
it 'renders page when diff size is not persisted and diff_refs does not exist' do
diff = merge_request.merge_request_diff
diff.clean!
diff.update!(real_size: nil,
start_commit_sha: nil,
base_commit_sha: nil)
go(format: :html)
expect(response).to be_success
end
end
it "renders merge request page" do
go(format: :html)

View file

@ -82,6 +82,14 @@ describe MergeRequestDiff do
diff.diffs
end
it 'returns persisted diffs if diff refs does not exist' do
expect(diff).to receive(:load_diffs)
diff.update!(start_commit_sha: nil, base_commit_sha: nil)
diff.diffs
end
end
end