diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-07-17 23:19:22 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-07-18 12:53:19 +0300 |
commit | 3ecc2b04a3f9c2dfad73b320bf54f5c9913204c0 (patch) | |
tree | b852b8f1c172437bb05958e84566bbe49fa5edcc | |
parent | 2f16eab03d8af372ae8461de5abf91b480ffd761 (diff) |
Render MR page when no persisted diff_refs or diffs size
4 files changed, 31 insertions, 1 deletions
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 3d72c447b4b..a073bbfad20 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -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 diff --git a/changelogs/unreleased/osw-fallback-to-collection-when-no-diff-refs.yml b/changelogs/unreleased/osw-fallback-to-collection-when-no-diff-refs.yml new file mode 100644 index 00000000000..71a2d94fc55 --- /dev/null +++ b/changelogs/unreleased/osw-fallback-to-collection-when-no-diff-refs.yml @@ -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 diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index 444415011a9..1692f299552 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -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) diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb index ccc3ff861c5..0aee78ac12d 100644 --- a/spec/models/merge_request_diff_spec.rb +++ b/spec/models/merge_request_diff_spec.rb @@ -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 |