Commit 5b7c7090 authored by Phil Hughes's avatar Phil Hughes

Fixes diff metadata StartupJS URL not matching

With unified diffs we always send the view param as inline
this wasn't taken into account when setting up the startup JS
url.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/280579
parent 94d4a2b0
......@@ -69,7 +69,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
}
options = additional_attributes.merge(
diff_view: Feature.enabled?(:unified_diff_lines, @merge_request.project, default_enabled: true) ? "inline" : diff_view,
diff_view: unified_diff_lines_view_type(@merge_request.project),
merge_ref_head_diff: render_merge_ref_head_diff?
)
......
......@@ -481,7 +481,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
def endpoint_metadata_url(project, merge_request)
params = request.query_parameters
params[:view] = cookies[:diff_view] if params[:view].blank? && cookies[:diff_view].present?
params[:view] = unified_diff_lines_view_type(project)
if Feature.enabled?(:default_merge_ref_for_diffs, project)
params = params.merge(diff_head: true)
......
......@@ -203,6 +203,14 @@ module DiffHelper
set_secure_cookie(:diff_view, params.delete(:view), type: CookiesHelper::COOKIE_TYPE_PERMANENT) if params[:view].present?
end
def unified_diff_lines_view_type(project)
if Feature.enabled?(:unified_diff_lines, project, default_enabled: true)
'inline'
else
diff_view
end
end
private
def diff_btn(title, name, selected)
......
---
title: Fixed diff metadata endpoint being called twice
merge_request: 47265
author:
type: fixed
......@@ -95,7 +95,8 @@ RSpec.describe Projects::MergeRequestsController do
project,
merge_request,
'json',
diff_head: true))
diff_head: true,
view: 'inline'))
end
end
......
......@@ -358,4 +358,30 @@ RSpec.describe DiffHelper do
expect(diff_file_path_text(diff_file, max: 10)).to eq("...open.rb")
end
end
describe 'unified_diff_lines_view_type' do
before do
controller.params[:view] = 'parallel'
end
describe 'unified diffs enabled' do
before do
stub_feature_flags(unified_diff_lines: true)
end
it 'returns inline view' do
expect(helper.unified_diff_lines_view_type(project)).to eq 'inline'
end
end
describe 'unified diffs disabled' do
before do
stub_feature_flags(unified_diff_lines: false)
end
it 'returns parallel view' do
expect(helper.unified_diff_lines_view_type(project)).to eq :parallel
end
end
end
end
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