Commit 903b8a54 authored by Alexandru Croitor's avatar Alexandru Croitor

Allow promoting issue to epic in custom groups

When promoting an issue to an epic we should be able to specify in which
group the new epic is supposed to be created.
parent 1af30cd8
...@@ -4,9 +4,9 @@ module Epics ...@@ -4,9 +4,9 @@ module Epics
class IssuePromoteService < ::Issuable::Clone::BaseService class IssuePromoteService < ::Issuable::Clone::BaseService
PromoteError = Class.new(StandardError) PromoteError = Class.new(StandardError)
def execute(issue) def execute(issue, epic_group = nil)
@issue = issue @issue = issue
@parent_group = issue.project.group @parent_group = epic_group || issue.project.group
validate_promotion! validate_promotion!
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
RSpec.describe Epics::IssuePromoteService do RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:group) { create(:group) } let(:group) { create(:group) }
let(:project) { create(:project, group: group) } let(:project) { create(:project, group: group) }
...@@ -41,8 +41,11 @@ RSpec.describe Epics::IssuePromoteService do ...@@ -41,8 +41,11 @@ RSpec.describe Epics::IssuePromoteService do
end end
context 'when a user can promote the issue' do context 'when a user can promote the issue' do
let(:new_group) { create(:group) }
before do before do
group.add_developer(user) group.add_developer(user)
new_group.add_developer(user)
end end
context 'when an issue does not belong to a group' do context 'when an issue does not belong to a group' do
...@@ -118,6 +121,19 @@ RSpec.describe Epics::IssuePromoteService do ...@@ -118,6 +121,19 @@ RSpec.describe Epics::IssuePromoteService do
end end
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 context 'when an issue belongs to an epic' do
let(:parent_epic) { create(:epic, group: group) } let(:parent_epic) { create(:epic, group: group) }
let!(:epic_issue) { create(:epic_issue, epic: parent_epic, issue: issue) } let!(:epic_issue) { create(:epic_issue, epic: parent_epic, issue: issue) }
...@@ -131,6 +147,35 @@ RSpec.describe Epics::IssuePromoteService do ...@@ -131,6 +147,35 @@ RSpec.describe Epics::IssuePromoteService do
expect(epic.group).to eq(group) expect(epic.group).to eq(group)
expect(epic.parent).to eq(parent_epic) expect(epic.parent).to eq(parent_epic)
end 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 end
context 'when issue was already promoted' do 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