From fdfb4bbe5c659e02734258615b57b5f012afb2b4 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Fri, 28 Jul 2017 13:59:57 +0100 Subject: Fix diff commenting results just after changing view When you change the diff view (inline / side-by-side), we set a cookie based on that new view. When you add a comment, we choose the style to use in the response based on that cookie. However, when you have just changed diff style, the request cookie will contain the old value, so we should use the view param instead. --- app/helpers/diff_helper.rb | 2 +- ...a-wrong-place-after-changing-diff-view-to-inline.yml | 4 ++++ spec/helpers/diff_helper_spec.rb | 17 +++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/35695-comment-appears-in-a-wrong-place-after-changing-diff-view-to-inline.yml diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 926502bf239..91ddd73fac1 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -15,7 +15,7 @@ module DiffHelper def diff_view @diff_view ||= begin diff_views = %w(inline parallel) - diff_view = cookies[:diff_view] + diff_view = params[:view] || cookies[:diff_view] diff_view = diff_views.first unless diff_views.include?(diff_view) diff_view.to_sym end diff --git a/changelogs/unreleased/35695-comment-appears-in-a-wrong-place-after-changing-diff-view-to-inline.yml b/changelogs/unreleased/35695-comment-appears-in-a-wrong-place-after-changing-diff-view-to-inline.yml new file mode 100644 index 00000000000..1c9ad20bc95 --- /dev/null +++ b/changelogs/unreleased/35695-comment-appears-in-a-wrong-place-after-changing-diff-view-to-inline.yml @@ -0,0 +1,4 @@ +--- +title: Fix display of new diff comments after changing b between diff views +merge_request: +author: diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb index 0d909e6e140..060c112e20d 100644 --- a/spec/helpers/diff_helper_spec.rb +++ b/spec/helpers/diff_helper_spec.rb @@ -12,19 +12,32 @@ describe DiffHelper do let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: diff_refs, repository: repository) } describe 'diff_view' do + it 'uses the view param over the cookie' do + controller.params[:view] = 'parallel' + helper.request.cookies[:diff_view] = 'inline' + + expect(helper.diff_view).to eq :parallel + end + + it 'returns the default value when the view param is invalid' do + controller.params[:view] = 'invalid' + + expect(helper.diff_view).to eq :inline + end + it 'returns a valid value when cookie is set' do helper.request.cookies[:diff_view] = 'parallel' expect(helper.diff_view).to eq :parallel end - it 'returns a default value when cookie is invalid' do + it 'returns the default value when cookie is invalid' do helper.request.cookies[:diff_view] = 'invalid' expect(helper.diff_view).to eq :inline end - it 'returns a default value when cookie is nil' do + it 'returns the default value when cookie is nil' do expect(helper.request.cookies).to be_empty expect(helper.diff_view).to eq :inline -- cgit v1.2.1