Commit b06b4736 authored by Josianne Hyson's avatar Josianne Hyson

Add Board Milestones to Group export

We want to be able to export the milestones on Boards for groups as
well.

Prior to this change, adding `:milestone` to the export config file
would result in an error when the `serialize_hash` method was called on
the MilestoneStruct, which is used for predefined, system wide
milestones.

Add this method to the struct so that it responds to the needed
interface and add `:milestone` to the config file for export.
parent 4b383fa1
......@@ -3,7 +3,13 @@
class Milestone < ApplicationRecord
# Represents a "No Milestone" state used for filtering Issues and Merge
# Requests that have no milestone assigned.
MilestoneStruct = Struct.new(:title, :name, :id)
MilestoneStruct = Struct.new(:title, :name, :id) do
# Ensure these models match the interface required for exporting
def serializable_hash(_opts = {})
{ title: title, name: name, id: id }
end
end
None = MilestoneStruct.new('No Milestone', 'No Milestone', 0)
Any = MilestoneStruct.new('Any Milestone', '', -1)
Upcoming = MilestoneStruct.new('Upcoming', '#upcoming', -2)
......
......@@ -138,6 +138,51 @@ describe Gitlab::ImportExport::Group::TreeSaver do
expect(assignee_list['user_id']).to eq(user.id)
end
end
context 'when there are boards with predefined milestones' do
let(:milestone) { Milestone::Upcoming }
before do
create(:board, group: group, milestone_id: milestone.id)
end
it 'saves the milestone data' do
expect_successful_save(group_tree_saver)
board_data = saved_group_json['boards'].last
expect(board_data).to include(
'milestone_id' => milestone.id,
'milestone' => {
'id' => milestone.id,
'name' => milestone.name,
'title' => milestone.title
}
)
end
end
context 'when there are boards with persisted milestones' do
let(:milestone) { create(:milestone) }
before do
create(:board, group: group, milestone: milestone)
end
it 'saves the milestone data' do
expect_successful_save(group_tree_saver)
board_data = saved_group_json['boards'].last
expect(board_data).to include(
'milestone_id' => milestone.id,
'milestone' => a_hash_including(
'id' => milestone.id,
'title' => milestone.title
)
)
end
end
end
def expect_successful_save(group_tree_saver)
......
......@@ -70,6 +70,7 @@ ee:
- :push_event_payload
- boards:
- :board_assignee
- :milestone
- labels:
- :priorities
- lists:
......
......@@ -189,7 +189,7 @@ describe Gitlab::ImportExport::Group::TreeSaver do
create(:group_badge, group: group)
group_label = create(:group_label, group: group)
create(:label_priority, label: group_label, priority: 1)
board = create(:board, group: group)
board = create(:board, group: group, milestone_id: Milestone::Upcoming.id)
create(:list, board: board, label: group_label)
create(:group_badge, group: group)
......
......@@ -3,6 +3,18 @@
require 'spec_helper'
describe Milestone do
describe 'MilestoneStruct#serializable_hash' do
let(:predefined_milestone) { described_class::MilestoneStruct.new('Test Milestone', '#test', 1) }
it 'presents the predefined milestone as a hash' do
expect(predefined_milestone.serializable_hash).to eq(
title: predefined_milestone.title,
name: predefined_milestone.name,
id: predefined_milestone.id
)
end
end
describe 'modules' do
context 'with a project' do
it_behaves_like 'AtomicInternalId' 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