Commit 6fa698bc authored by Peter Leitzen's avatar Peter Leitzen Committed by Heinrich Lee Yu

Fix quick action spec for `/promote` when passing project without group

Previously, we've passed the wrong project (top level `project`
instead of `user_project`) to the `QuickActionsService` so
the `condition` check passed, called `IssuePromoteService` which
raised a `PromoteError`.
parent 39bc3609
......@@ -24,6 +24,7 @@ module Epics
raise PromoteError, _('Cannot promote issue because it does not belong to a group.') if parent_group.nil?
raise PromoteError, _('Cannot promote issue due to insufficient permissions.') unless can_promote?
raise PromoteError, _('Issue already promoted to epic.') if issue.promoted?
raise PromoteError, _('Promotion is not supported.') unless issue.supports_epic?
end
def can_promote?
......
......@@ -71,6 +71,7 @@ module EE
types Issue
condition do
quick_action_target.persisted? &&
quick_action_target.supports_epic? &&
!quick_action_target.promoted? &&
current_user.can?(:admin_issue, project) &&
current_user.can?(:create_epic, project.group)
......
......@@ -377,24 +377,33 @@ RSpec.describe Notes::QuickActionsService do
context 'when issue was already promoted' do
it 'does not promote issue' do
issue.update(promoted_to_epic_id: epic.id)
issue.update!(promoted_to_epic_id: epic.id)
expect { execute(note) }.not_to change { Epic.count }
end
end
context 'when an issue belongs to a project without group' do
let(:user_project) { create(:project) }
let(:issue) { create(:issue, project: user_project) }
let(:note) { create(:note_on_issue, noteable: issue, project: user_project, note: note_text) }
let(:project) { create(:project) }
let(:issue) { create(:issue, project: project) }
let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) }
before do
user_project.add_developer(user)
project.add_developer(user)
end
it 'does not promote an issue to an epic' do
expect { execute(note) }
.to raise_error(Epics::IssuePromoteService::PromoteError)
expect { execute(note) }.not_to change { Epic.count }
end
end
context 'on an incident' do
before do
issue.update!(issue_type: :incident)
end
it 'does not promote to an epic' do
expect { execute(note) }.not_to change { Epic.count }
end
end
end
......
......@@ -167,6 +167,15 @@ RSpec.describe Epics::IssuePromoteService do
expect(epic.notes.user.first.attachment).to be_kind_of(AttachmentUploader)
end
end
context 'on an incident' do
it 'raises error' do
issue.update!(issue_type: :incident)
expect { subject.execute(issue) }
.to raise_error(Epics::IssuePromoteService::PromoteError, /is not supported/)
end
end
end
end
end
......
......@@ -20002,6 +20002,9 @@ msgstr ""
msgid "Promoted issue to an epic."
msgstr ""
msgid "Promotion is not supported."
msgstr ""
msgid "Promotions|Burndown Charts are visual representations of the progress of completing a milestone. At a glance, you see the current state for the completion a given milestone. Without them, you would have to organize the data from the milestone and plot it yourself to have the same sense of progress."
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