Commit 77f2d364 authored by Toon Claes's avatar Toon Claes

Move specs to interpret_service_spec.rb

And some other little cleanups.
parent 87ed4efa
......@@ -57,7 +57,7 @@ discussions, and descriptions:
| `/approve` | Approve the merge request | | ✓ |
| `/merge` | Merge (when pipeline succeeds) | | ✓ |
| `/create_merge_request <branch name>` | Create a new merge request starting from the current issue | ✓ | |
| `/relate #issue [#issue...]`| Mark issues as related | ✓ | |
| `/relate #issue1 #issue2` | Mark issues as related **[STARTER]** | ✓ | |
## Quick actions for commit messages
......
......@@ -8,7 +8,6 @@ module EE
override :execute
def execute(issue)
handle_epic(issue)
handle_relate(issue)
result = super
if issue.previous_changes.include?(:milestone_id) && issue.epic
......@@ -35,18 +34,6 @@ module EE
EpicIssues::DestroyService.new(link, current_user).execute
end
end
def handle_relate(issue)
return unless params.key?(:related_issues)
relate_param = params.delete(:related_issues)
if relate_param
relate_param.each do |issuable|
IssueLinks::CreateService.new(issuable, current_user, { target_issue: issue }).execute
end
end
end
end
end
end
......@@ -10,7 +10,7 @@ module EE
included do
desc _('Mark this issue as related to another issue')
explanation do |related_reference|
_('Marks this issue related to %{issue_ref}.') % { issue_ref: related_reference }
_('Marks this issue as related to %{issue_ref}.') % { issue_ref: related_reference }
end
params '#issue'
types Issue
......
......@@ -258,93 +258,43 @@ describe Notes::QuickActionsService do
end
end
context '/relate command' do
shared_examples 'relate command' do
let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) }
context '/relate' do
let(:other_issue) { create(:issue, project: project) }
let(:note_text) { "/relate #{other_issue.to_reference}" }
let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) }
it 'relates issues' do
execute(note)
context 'user cannot relate issues' do
before do
project.update(visibility: Gitlab::VisibilityLevel::PUBLIC)
end
expect(issue.related_issues(user)).to match_array(issues_related)
it 'does not create issue relation' do
expect { execute(note) }.not_to change { IssueLink.count }
end
end
context 'user is member of project' do
context 'user is allowed to relate issues' do
before do
group.add_developer(user)
end
context 'relate a single issue' do
let(:other_issue) { create(:issue, project: project) }
let(:issues_related) { [other_issue] }
let(:note_text) { "/relate #{other_issue.to_reference}" }
it_behaves_like 'relate command'
end
context 'relate multiple issues at once' do
let(:second_issue) { create(:issue, project: project) }
let(:third_issue) { create(:issue, project: project) }
let(:issues_related) { [second_issue, third_issue] }
let(:note_text) { "/relate #{second_issue.to_reference} #{third_issue.to_reference}" }
it_behaves_like 'relate command'
end
context 'empty relate command' do
let(:issues_related) { [] }
let(:note_text) { '/relate' }
it_behaves_like 'relate command'
end
context 'already having related issues' do
let(:second_issue) { create(:issue, project: project) }
let(:third_issue) { create(:issue, project: project) }
let(:issues_related) { [second_issue, third_issue] }
let(:note_text) { "/relate #{third_issue.to_reference(project)}" }
context 'related issues are not enabled' do
before do
create(:issue_link, source: issue, target: second_issue)
end
it_behaves_like 'relate command'
end
context 'cross project' do
let(:other_project) { create(:project, group: group) }
context 'relate a cross project issue' do
let(:other_issue) { create(:issue, project: other_project) }
let(:issues_related) { [other_issue] }
let(:note_text) { "/relate #{other_issue.to_reference(project)}" }
it_behaves_like 'relate command'
stub_licensed_features(related_issues: false)
end
context 'relate multiple cross projects issues at once' do
let(:second_issue) { create(:issue, project: other_project) }
let(:third_issue) { create(:issue, project: other_project) }
let(:issues_related) { [second_issue, third_issue] }
let(:note_text) { "/relate #{second_issue.to_reference(project)} #{third_issue.to_reference(project)}" }
it_behaves_like 'relate command'
it 'does not create issue relation' do
expect { execute(note) }.not_to change { IssueLink.count }
end
end
context 'relate an non-existing issue' do
let(:issues_related) { [] }
let(:note_text) { "/relate imaginary#1234" }
it_behaves_like 'relate command'
context 'related issues are enabled' do
before do
stub_licensed_features(related_issues: true)
end
context 'relate a private issue' do
let(:private_project) { create(:project, :private) }
let(:other_issue) { create(:issue, project: private_project) }
let(:issues_related) { [] }
let(:note_text) { "/relate #{other_issue.to_reference(project)}" }
it_behaves_like 'relate command'
it 'creates issue relation' do
expect { execute(note) }.to change { IssueLink.count }.by(1)
end
end
end
......
......@@ -753,6 +753,101 @@ describe QuickActions::InterpretService do
let(:issuable) { build(:merge_request, source_project: project) }
end
end
context 'relate command' do
shared_examples 'relate command' do
it 'relates issues' do
service.execute(content, issue)
expect(IssueLink.where(source: issue).map(&:target)).to match_array(issues_related)
end
end
context 'user is member of group' do
before do
group.add_developer(user)
end
context 'relate a single issue' do
let(:other_issue) { create(:issue, project: project) }
let(:issues_related) { [other_issue] }
let(:content) { "/relate #{other_issue.to_reference}" }
it_behaves_like 'relate command'
end
context 'relate multiple issues at once' do
let(:second_issue) { create(:issue, project: project) }
let(:third_issue) { create(:issue, project: project) }
let(:issues_related) { [second_issue, third_issue] }
let(:content) { "/relate #{second_issue.to_reference} #{third_issue.to_reference}" }
it_behaves_like 'relate command'
end
context 'empty relate command' do
let(:issues_related) { [] }
let(:content) { '/relate' }
it_behaves_like 'relate command'
end
context 'already having related issues' do
let(:second_issue) { create(:issue, project: project) }
let(:third_issue) { create(:issue, project: project) }
let(:issues_related) { [second_issue, third_issue] }
let(:content) { "/relate #{third_issue.to_reference(project)}" }
before do
create(:issue_link, source: issue, target: second_issue)
end
it_behaves_like 'relate command'
end
context 'cross project' do
let(:another_group) { create(:group, :public) }
let(:other_project) { create(:project, group: another_group) }
before do
another_group.add_developer(current_user)
end
context 'relate a cross project issue' do
let(:other_issue) { create(:issue, project: other_project) }
let(:issues_related) { [other_issue] }
let(:content) { "/relate #{other_issue.to_reference(project)}" }
it_behaves_like 'relate command'
end
context 'relate multiple cross projects issues at once' do
let(:second_issue) { create(:issue, project: other_project) }
let(:third_issue) { create(:issue, project: other_project) }
let(:issues_related) { [second_issue, third_issue] }
let(:content) { "/relate #{second_issue.to_reference(project)} #{third_issue.to_reference(project)}" }
it_behaves_like 'relate command'
end
context 'relate a non-existing issue' do
let(:issues_related) { [] }
let(:content) { "/relate imaginary#1234" }
it_behaves_like 'relate command'
end
context 'relate a private issue' do
let(:private_project) { create(:project, :private) }
let(:other_issue) { create(:issue, project: private_project) }
let(:issues_related) { [] }
let(:content) { "/relate #{other_issue.to_reference(project)}" }
it_behaves_like 'relate command'
end
end
end
end
end
describe '#explain' do
......
......@@ -8178,6 +8178,9 @@ msgstr ""
msgid "Mark this issue as a duplicate of another issue"
msgstr ""
msgid "Mark this issue as related to another issue"
msgstr ""
msgid "Mark todo as done"
msgstr ""
......@@ -8193,6 +8196,9 @@ msgstr ""
msgid "Marks this issue as a duplicate of %{duplicate_reference}."
msgstr ""
msgid "Marks this issue as related to %{issue_ref}."
msgstr ""
msgid "Marks todo as done."
msgstr ""
......
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