Commit 31e26803 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Allow ancestor group milestones for issue boards

We already show these milestones in the dropdown so we
should allow setting of these milestones
parent 00d0ad06
......@@ -20,12 +20,12 @@ module Boards
finder_params =
if parent.is_a?(Group)
{
group_ids: parent.self_and_ancestors_ids
group_ids: parent.self_and_ancestors
}
else
{
project_ids: [parent.id],
group_ids: parent.group&.self_and_ancestors_ids
group_ids: parent.group&.self_and_ancestors
}
end
......
......@@ -25,9 +25,9 @@ module EE
finder_params =
case parent
when Group
{ group_ids: [parent.id] }
{ group_ids: parent.self_and_ancestors }
when Project
{ project_ids: [parent.id], group_ids: [parent.group&.id] }
{ project_ids: [parent.id], group_ids: parent.group&.self_and_ancestors }
end
milestone = ::MilestonesFinder.new(finder_params).find_by(id: milestone_id)
......
---
title: Allow ancestor group milestones in issue board scope
merge_request: 15858
author:
type: fixed
require 'spec_helper'
describe Boards::CreateService, services: true do
shared_examples 'board with milestone predefined scope' do
let(:project) { create(:project) }
it 'creates board with correct milestone' do
stub_licensed_features(scoped_issue_board: true)
board = described_class
.new(project, double, milestone_id: milestone_class.id)
.execute
expect(board.reload.milestone).to eq(milestone_class)
end
end
shared_examples 'boards create service' do
context 'With the feature available' do
before do
......@@ -85,76 +71,8 @@ describe Boards::CreateService, services: true do
end
end
it_behaves_like 'board with milestone predefined scope' do
let(:milestone_class) { ::Milestone::Upcoming }
end
it_behaves_like 'board with milestone predefined scope' do
let(:milestone_class) { ::Milestone::Started }
end
context 'group board milestone' do
let(:group) { create(:group) }
let!(:milestone) { create(:milestone) }
before do
stub_licensed_features(scoped_issue_board: true)
end
it 'is not persisted if it is not within group milestones' do
service = described_class.new(group, double, milestone_id: milestone.id)
group_board = service.execute
expect(group_board.milestone).to be_nil
end
it 'is persisted if it is within group milestones' do
milestone.update!(project: nil, group: group)
service = described_class.new(group, double, milestone_id: milestone.id)
group_board = service.execute
expect(group_board.reload.milestone).to eq(milestone)
end
end
context 'project board milestone' do
let(:project) { create(:project, :private) }
let!(:milestone) { create(:milestone) }
before do
stub_licensed_features(scoped_issue_board: true)
end
it 'is not persisted if it is not within project milestones' do
service = described_class.new(project, double, milestone_id: milestone.id)
board = service.execute
expect(board.reload.milestone).to be_nil
end
it 'is persisted if it is within project milestones' do
milestone.update!(project: project)
service = described_class.new(project, double, milestone_id: milestone.id)
board = service.execute
expect(board.reload.milestone).to eq(milestone)
end
it 'is persisted if it is within project group milestones' do
project_group = create(:group)
project.update(group: project_group)
milestone.update!(project: nil, group: project_group)
service = described_class.new(project_group, double, milestone_id: milestone.id)
board = service.execute
expect(board.reload.milestone).to eq(milestone)
end
it_behaves_like 'setting a milestone scope' do
subject { described_class.new(parent, double, milestone_id: milestone.id).execute }
end
end
end
require 'spec_helper'
describe Boards::UpdateService, services: true do
shared_examples 'board with milestone predefined scope' do
let(:project) { create(:project) }
let!(:board) { create(:board) }
it 'updates board to milestone id' do
stub_licensed_features(scoped_issue_board: true)
described_class
.new(project, double, milestone_id: milestone_class.id)
.execute(board)
expect(board.reload.milestone).to eq(milestone_class)
end
end
describe '#execute' do
let(:project) { create(:project, group: group) }
let(:group) { create(:group) }
......@@ -71,73 +56,11 @@ describe Boards::UpdateService, services: true do
labels: [])
end
it_behaves_like 'board with milestone predefined scope' do
let(:milestone_class) { ::Milestone::Upcoming }
end
it_behaves_like 'board with milestone predefined scope' do
let(:milestone_class) { ::Milestone::Started }
end
context 'group board milestone' do
let!(:milestone) { create(:milestone) }
before do
stub_licensed_features(scoped_issue_board: true)
end
it 'is not updated if it is not within group milestones' do
service = described_class.new(group, double, milestone_id: milestone.id)
service.execute(board)
expect(board.reload.milestone).to be_nil
end
it 'is updated if it is within group milestones' do
milestone.update!(project: nil, group: group)
service = described_class.new(group, double, milestone_id: milestone.id)
service.execute(board)
expect(board.reload.milestone).to eq(milestone)
end
end
context 'project board milestone' do
let!(:milestone) { create(:milestone) }
it_behaves_like 'setting a milestone scope' do
subject { board.reload }
before do
stub_licensed_features(scoped_issue_board: true)
end
it 'is not updated if it is not within project milestones' do
service = described_class.new(project, double, milestone_id: milestone.id)
service.execute(board)
expect(board.reload.milestone).to be_nil
end
it 'is updated if it is within project milestones' do
milestone.update!(project: project)
service = described_class.new(project, double, milestone_id: milestone.id)
service.execute(board)
expect(board.reload.milestone).to eq(milestone)
end
it 'is updated if it is within project group milestones' do
project_group = create(:group)
project.update(group: project_group)
milestone.update!(project: nil, group: project_group)
service = described_class.new(project_group, double, milestone_id: milestone.id)
service.execute(board)
expect(board.reload.milestone).to eq(milestone)
described_class.new(parent, double, milestone_id: milestone.id).execute(board)
end
end
......
# frozen_string_literal: true
shared_examples 'setting a milestone scope' do
before do
stub_licensed_features(scoped_issue_board: true)
end
shared_examples 'an invalid milestone' do
context 'when milestone is from another project / group' do
let(:milestone) { create(:milestone) }
it { expect(subject.milestone).to be_nil }
end
end
shared_examples 'a predefined milestone' do
context 'Upcoming' do
let(:milestone) { ::Milestone::Upcoming }
it { expect(subject.milestone).to eq(milestone) }
end
context 'Started' do
let(:milestone) { ::Milestone::Started }
it { expect(subject.milestone).to eq(milestone) }
end
end
shared_examples 'a group milestone' do
context 'when milestone is a group milestone' do
let(:milestone) { create(:milestone, group: group) }
it { expect(subject.milestone).to eq(milestone) }
end
context 'when milestone is an an ancestor group milestone' do
let(:milestone) { create(:milestone, group: ancestor_group) }
it { expect(subject.milestone).to eq(milestone) }
end
end
let(:ancestor_group) { create(:group) }
let(:group) { create(:group, parent: ancestor_group) }
context 'for a group board' do
let(:parent) { group }
it_behaves_like 'an invalid milestone'
it_behaves_like 'a predefined milestone'
it_behaves_like 'a group milestone'
end
context 'for a project board' do
let(:project) { create(:project, :private, group: group) }
let(:parent) { project }
it_behaves_like 'an invalid milestone'
it_behaves_like 'a predefined milestone'
it_behaves_like 'a group milestone'
context 'when milestone is a project milestone' do
let(:milestone) { create(:milestone, project: project) }
it { expect(subject.milestone).to eq(milestone) }
end
end
end
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