summaryrefslogtreecommitdiff
path: root/spec/helpers/notes_helper_spec.rb
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-05-05 12:31:10 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-05-05 12:31:10 +0200
commite944fd7064b5a04a334b6c500c9ee7db29a46538 (patch)
tree7418e54f3774ca676040a16a30a4a9cd7c922100 /spec/helpers/notes_helper_spec.rb
parent3aa92cb5cbe8456c845e16d14489591dd81dbcb3 (diff)
parent3a2b60f7a0109cdb84e8727a2625318a746e84dc (diff)
downloadgitlab-ce-e944fd7064b5a04a334b6c500c9ee7db29a46538.tar.gz
* commit '3a2b60f7a0109cdb84e8727a2625318a746e84dc': (254 commits) Fixed Karma spec Reject EE reserved namespace paths in CE as well Updated webpack config Include the bundler:audit job into the static-analysis job Document serializers Add artifact file page that uses the blob viewer Pipeline table mini graph dropdown remains open when table is refreshed Adds off for event hub Compile gitlab-shell go executables Allow to create new branch and empty WIP merge request from issue page Moved to a view spec Improving copy of CONTRIBUTING.md, PROCESS.md, and code_review.md Convert seconds to minutes and hours on chat notifations Disable navigation to Pages config if Pages is disabled Sort the network graph both by commit date and topographically. Add tooltips to note action buttons Add breadcrumb, build header and pipelines submenu to artifacts browser Update todos screenshots removes the possibility of commit messages having carriage returns Handle incoming emails from aliases correctly ...
Diffstat (limited to 'spec/helpers/notes_helper_spec.rb')
-rw-r--r--spec/helpers/notes_helper_spec.rb139
1 files changed, 139 insertions, 0 deletions
diff --git a/spec/helpers/notes_helper_spec.rb b/spec/helpers/notes_helper_spec.rb
index a427de32c4c..6c990f94175 100644
--- a/spec/helpers/notes_helper_spec.rb
+++ b/spec/helpers/notes_helper_spec.rb
@@ -1,6 +1,8 @@
require "spec_helper"
describe NotesHelper do
+ include RepoHelpers
+
let(:owner) { create(:owner) }
let(:group) { create(:group) }
let(:project) { create(:empty_project, namespace: group) }
@@ -36,4 +38,141 @@ describe NotesHelper do
expect(helper.note_max_access_for_user(other_note)).to eq('Reporter')
end
end
+
+ describe '#discussion_path' do
+ let(:project) { create(:project) }
+
+ context 'for a merge request discusion' do
+ let(:merge_request) { create(:merge_request, source_project: project, target_project: project, importing: true) }
+ let!(:merge_request_diff1) { merge_request.merge_request_diffs.create(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') }
+ let!(:merge_request_diff2) { merge_request.merge_request_diffs.create(head_commit_sha: nil) }
+ let!(:merge_request_diff3) { merge_request.merge_request_diffs.create(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') }
+
+ context 'for a diff discussion' do
+ context 'when the discussion is active' do
+ let(:discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion }
+
+ it 'returns the diff path with the line code' do
+ expect(helper.discussion_path(discussion)).to eq(diffs_namespace_project_merge_request_path(project.namespace, project, merge_request, anchor: discussion.line_code))
+ end
+ end
+
+ context 'when the discussion is on an older merge request version' do
+ let(:position) do
+ Gitlab::Diff::Position.new(
+ old_path: ".gitmodules",
+ new_path: ".gitmodules",
+ old_line: nil,
+ new_line: 4,
+ diff_refs: merge_request_diff1.diff_refs
+ )
+ end
+
+ let(:diff_note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project, position: position) }
+ let(:discussion) { diff_note.to_discussion }
+
+ before do
+ diff_note.position = diff_note.original_position
+ diff_note.save!
+ end
+
+ it 'returns the diff version path with the line code' do
+ expect(helper.discussion_path(discussion)).to eq(diffs_namespace_project_merge_request_path(project.namespace, project, merge_request, diff_id: merge_request_diff1, anchor: discussion.line_code))
+ end
+ end
+
+ context 'when the discussion is on a comparison between merge request versions' do
+ let(:position) do
+ Gitlab::Diff::Position.new(
+ old_path: ".gitmodules",
+ new_path: ".gitmodules",
+ old_line: 4,
+ new_line: 4,
+ diff_refs: merge_request_diff3.compare_with(merge_request_diff1.head_commit_sha).diff_refs
+ )
+ end
+
+ let(:discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project, position: position).to_discussion }
+
+ it 'returns the diff version comparison path with the line code' do
+ expect(helper.discussion_path(discussion)).to eq(diffs_namespace_project_merge_request_path(project.namespace, project, merge_request, diff_id: merge_request_diff3, start_sha: merge_request_diff1.head_commit_sha, anchor: discussion.line_code))
+ end
+ end
+
+ context 'when the discussion does not have a merge request version' do
+ let(:outdated_diff_note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project, diff_refs: project.commit(sample_commit.id).diff_refs) }
+ let(:discussion) { outdated_diff_note.to_discussion }
+
+ before do
+ outdated_diff_note.position = outdated_diff_note.original_position
+ outdated_diff_note.save!
+ end
+
+ it 'returns nil' do
+ expect(helper.discussion_path(discussion)).to be_nil
+ end
+ end
+ end
+
+ context 'for a legacy diff discussion' do
+ let(:discussion) { create(:legacy_diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion }
+
+ context 'when the discussion is active' do
+ before do
+ allow(discussion).to receive(:active?).and_return(true)
+ end
+
+ it 'returns the diff path with the line code' do
+ expect(helper.discussion_path(discussion)).to eq(diffs_namespace_project_merge_request_path(project.namespace, project, merge_request, anchor: discussion.line_code))
+ end
+ end
+
+ context 'when the discussion is outdated' do
+ before do
+ allow(discussion).to receive(:active?).and_return(false)
+ end
+
+ it 'returns nil' do
+ expect(helper.discussion_path(discussion)).to be_nil
+ end
+ end
+ end
+
+ context 'for a non-diff discussion' do
+ let(:discussion) { create(:discussion_note_on_merge_request, noteable: merge_request, project: project).to_discussion }
+
+ it 'returns nil' do
+ expect(helper.discussion_path(discussion)).to be_nil
+ end
+ end
+ end
+
+ context 'for a commit discussion' do
+ let(:commit) { discussion.noteable }
+
+ context 'for a diff discussion' 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(namespace_project_commit_path(project.namespace, project, commit, anchor: discussion.line_code))
+ end
+ end
+
+ context 'for a legacy diff discussion' 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(namespace_project_commit_path(project.namespace, project, commit, anchor: discussion.line_code))
+ end
+ end
+
+ context 'for a non-diff discussion' do
+ let(:discussion) { create(:discussion_note_on_commit, project: project).to_discussion }
+
+ it 'returns the commit path' do
+ expect(helper.discussion_path(discussion)).to eq(namespace_project_commit_path(project.namespace, project, commit))
+ end
+ end
+ end
+ end
end