Commit 1e9d248b authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'id-fix-no-route-error' into 'master'

Fix viewing blobs for broken MRs

See merge request gitlab-org/gitlab!52483
parents a30776e0 47ea7093
...@@ -254,7 +254,7 @@ module DiffHelper ...@@ -254,7 +254,7 @@ module DiffHelper
end end
def code_navigation_path(diffs) def code_navigation_path(diffs)
Gitlab::CodeNavigationPath.new(merge_request.project, diffs.diff_refs&.head_sha) Gitlab::CodeNavigationPath.new(merge_request.project, merge_request.diff_head_sha)
end end
def conflicts def conflicts
......
...@@ -79,7 +79,9 @@ class DiffsEntity < Grape::Entity ...@@ -79,7 +79,9 @@ class DiffsEntity < Grape::Entity
end end
expose :definition_path_prefix do |diffs| expose :definition_path_prefix do |diffs|
project_blob_path(merge_request.project, diffs.diff_refs&.head_sha) next unless merge_request.diff_head_sha
project_blob_path(merge_request.project, merge_request.diff_head_sha)
end end
def merge_request def merge_request
......
---
title: Fix viewing blobs for broken MRs
merge_request: 52483
author:
type: fixed
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe DiffsEntity do RSpec.describe DiffsEntity do
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let_it_be(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
let(:request) { EntityRequest.new(project: project, current_user: user) } let(:request) { EntityRequest.new(project: project, current_user: user) }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
let(:merge_request_diffs) { merge_request.merge_request_diffs } let(:merge_request_diffs) { merge_request.merge_request_diffs }
let(:options) do let(:options) do
{ request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs } { request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs }
...@@ -30,6 +31,14 @@ RSpec.describe DiffsEntity do ...@@ -30,6 +31,14 @@ RSpec.describe DiffsEntity do
) )
end end
context 'broken merge request' do
let(:merge_request) { create(:merge_request, :invalid, target_project: project, source_project: project) }
it 'renders without errors' do
expect { subject }.not_to raise_error
end
end
context "when a commit_id is passed" do context "when a commit_id is passed" do
let(:commits) { merge_request.commits } let(:commits) { merge_request.commits }
let(:entity) do let(:entity) 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