Commit 1e64a81f authored by Stan Hu's avatar Stan Hu

Merge branch '233974-promote-issue-to-epic-refactoring' into 'master'

Allow promoting issue to epic in custom groups

See merge request gitlab-org/gitlab!46129
parents 8bd8ea37 903b8a54
......@@ -4,9 +4,9 @@ module Epics
class IssuePromoteService < ::Issuable::Clone::BaseService
PromoteError = Class.new(StandardError)
def execute(issue)
def execute(issue, epic_group = nil)
@issue = issue
@parent_group = issue.project.group
@parent_group = epic_group || issue.project.group
validate_promotion!
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Epics::IssuePromoteService do
RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
......@@ -41,8 +41,11 @@ RSpec.describe Epics::IssuePromoteService do
end
context 'when a user can promote the issue' do
let(:new_group) { create(:group) }
before do
group.add_developer(user)
new_group.add_developer(user)
end
context 'when an issue does not belong to a group' do
......@@ -118,6 +121,19 @@ RSpec.describe Epics::IssuePromoteService do
end
end
context 'when promoting issue to a different group' do
it 'creates a new epic with correct attributes' do
epic = subject.execute(issue, new_group)
expect(issue.reload.promoted_to_epic_id).to eq(epic.id)
expect(epic.title).to eq(issue.title)
expect(epic.description).to eq(issue.description)
expect(epic.author).to eq(user)
expect(epic.group).to eq(new_group)
expect(epic.parent).to be_nil
end
end
context 'when an issue belongs to an epic' do
let(:parent_epic) { create(:epic, group: group) }
let!(:epic_issue) { create(:epic_issue, epic: parent_epic, issue: issue) }
......@@ -131,6 +147,35 @@ RSpec.describe Epics::IssuePromoteService do
expect(epic.group).to eq(group)
expect(epic.parent).to eq(parent_epic)
end
context 'when promoting issue to a different group' do
it 'creates a new epic with correct attributes' do
expect { subject.execute(issue, new_group) }
.to raise_error(StandardError, 'Validation failed: Parent This epic cannot be added. An epic must belong to the same group or subgroup as its parent epic.')
expect(issue.reload.state).to eq("opened")
expect(issue.reload.promoted_to_epic_id).to be_nil
end
end
context 'when promoting issue to a different group in the hierarchy' do
let(:new_group) { create(:group, parent: group) }
before do
new_group.add_developer(user)
end
it 'creates a new epic with correct attributes' do
epic = subject.execute(issue, new_group)
expect(issue.reload.promoted_to_epic_id).to eq(epic.id)
expect(epic.title).to eq(issue.title)
expect(epic.description).to eq(issue.description)
expect(epic.author).to eq(user)
expect(epic.group).to eq(new_group)
expect(epic.parent).to eq(parent_epic)
end
end
end
context 'when issue was already promoted' do
......
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