diff options
author | ⛄️ Sean McGivern ⛄️ <sean@mcgivern.me.uk> | 2017-12-18 18:41:22 +0000 |
---|---|---|
committer | ⛄️ Sean McGivern ⛄️ <sean@mcgivern.me.uk> | 2017-12-18 18:41:22 +0000 |
commit | f7a9ced235be7ef13f90b561d23ffe602e11e9a3 (patch) | |
tree | ce4c79e0d07fe84ce3a75d319c2eb99e673a1e57 | |
parent | 08ee1e29f9beef1109930dedc74d3de3518b693b (diff) | |
parent | a794b161cd996f3328c0b9a60d0e3cbdaee2a914 (diff) | |
download | gitlab-ce-f7a9ced235be7ef13f90b561d23ffe602e11e9a3.tar.gz |
Merge branch 'commit-diff-discussion-in-mr-context-fix-links' into 'master'41248-datetime_utility-calls-a-missing-lang-export-function-from-locale-index-js
fix the commit diff discussion sending the wrong url
See merge request gitlab-org/gitlab-ce!15988
-rw-r--r-- | app/models/diff_discussion.rb | 15 | ||||
-rw-r--r-- | spec/helpers/notes_helper_spec.rb | 14 |
2 files changed, 22 insertions, 7 deletions
diff --git a/app/models/diff_discussion.rb b/app/models/diff_discussion.rb index 4a65738214b..d67b16584a4 100644 --- a/app/models/diff_discussion.rb +++ b/app/models/diff_discussion.rb @@ -22,12 +22,9 @@ class DiffDiscussion < Discussion def merge_request_version_params return unless for_merge_request? - return {} if active? - if on_merge_request_commit? - { commit_id: commit_id } - else - noteable.version_params_for(position.diff_refs) + version_params.tap do |params| + params[:commit_id] = commit_id if on_merge_request_commit? end end @@ -37,4 +34,12 @@ class DiffDiscussion < Discussion position: position.to_json ) end + + private + + def version_params + return {} if active? + + noteable.version_params_for(position.diff_refs) + end end diff --git a/spec/helpers/notes_helper_spec.rb b/spec/helpers/notes_helper_spec.rb index cd15e27b497..36a44f8567a 100644 --- a/spec/helpers/notes_helper_spec.rb +++ b/spec/helpers/notes_helper_spec.rb @@ -41,6 +41,7 @@ describe NotesHelper do describe '#discussion_path' do let(:project) { create(:project, :repository) } + let(:anchor) { discussion.line_code } context 'for a merge request discusion' do let(:merge_request) { create(:merge_request, source_project: project, target_project: project, importing: true) } @@ -151,6 +152,15 @@ describe NotesHelper do expect(helper.discussion_path(discussion)).to be_nil end end + + context 'for a contextual commit discussion' do + let(:commit) { merge_request.commits.last } + let(:discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project, commit_id: commit.id).to_discussion } + + it 'returns the merge request diff discussion scoped in the commit' do + expect(helper.discussion_path(discussion)).to eq(diffs_project_merge_request_path(project, merge_request, commit_id: commit.id, anchor: anchor)) + end + end end context 'for a commit discussion' do @@ -160,7 +170,7 @@ describe NotesHelper do let(:discussion) { create(:diff_note_on_commit, project: project).to_discussion } it 'returns the commit path with the line code' do - expect(helper.discussion_path(discussion)).to eq(project_commit_path(project, commit, anchor: discussion.line_code)) + expect(helper.discussion_path(discussion)).to eq(project_commit_path(project, commit, anchor: anchor)) end end @@ -168,7 +178,7 @@ describe NotesHelper do let(:discussion) { create(:legacy_diff_note_on_commit, project: project).to_discussion } it 'returns the commit path with the line code' do - expect(helper.discussion_path(discussion)).to eq(project_commit_path(project, commit, anchor: discussion.line_code)) + expect(helper.discussion_path(discussion)).to eq(project_commit_path(project, commit, anchor: anchor)) end end |