diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-09-07 19:08:56 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-04 22:49:41 +0200 |
commit | 518216c0627cb6c4b3db62f10877b44d0e912ddb (patch) | |
tree | 68a4aa0a3301728097e73c6e09c48780a1b52757 /spec | |
parent | 530cf2a2669ea1ee3c41d48a15919f875babefa4 (diff) | |
download | gitlab-ce-518216c0627cb6c4b3db62f10877b44d0e912ddb.tar.gz |
Merge group hierarchies when parents are shared
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/concerns/group_hierarchy_spec.rb | 68 | ||||
-rw-r--r-- | spec/serializers/group_child_serializer_spec.rb | 43 |
2 files changed, 111 insertions, 0 deletions
diff --git a/spec/models/concerns/group_hierarchy_spec.rb b/spec/models/concerns/group_hierarchy_spec.rb index 14ac910c90d..1f4fab88781 100644 --- a/spec/models/concerns/group_hierarchy_spec.rb +++ b/spec/models/concerns/group_hierarchy_spec.rb @@ -29,6 +29,40 @@ describe GroupHierarchy, :nested_groups do expect(subsub_group.parent).to eq(subgroup) end end + + describe '#merge_hierarchy' do + it 'combines hierarchies' do + other_subgroup = create(:group, parent: parent) + + expected_hierarchy = { parent => [{ subgroup => subsub_group }, other_subgroup] } + + expect(subsub_group.merge_hierarchy(other_subgroup)).to eq(expected_hierarchy) + end + end + + describe '.merge_hierarchies' do + it 'combines hierarchies until the top' do + other_subgroup = create(:group, parent: parent) + other_subsub_group = create(:group, parent: subgroup) + + groups = [other_subgroup, subsub_group, other_subsub_group] + + expected_hierarchy = { parent => [other_subgroup, { subgroup => [subsub_group, other_subsub_group] }] } + + expect(described_class.merge_hierarchies(groups)).to eq(expected_hierarchy) + end + + it 'combines upto a given parent' do + other_subgroup = create(:group, parent: parent) + other_subsub_group = create(:group, parent: subgroup) + + groups = [other_subgroup, subsub_group, other_subsub_group] + + expected_hierarchy = [other_subgroup, { subgroup => [subsub_group, other_subsub_group] }] + + expect(described_class.merge_hierarchies(groups, parent)).to eq(expected_hierarchy) + end + end end context 'for a project' do @@ -57,5 +91,39 @@ describe GroupHierarchy, :nested_groups do expect(project.parent).to eq(subsub_group) end end + + describe '#merge_hierarchy' do + it 'combines hierarchies' do + project = create(:project, namespace: parent) + + expected_hierarchy = { parent => [{ subgroup => subsub_group }, project] } + + expect(subsub_group.merge_hierarchy(project)).to eq(expected_hierarchy) + end + end + + describe '.merge_hierarchies' do + it 'combines hierarchies until the top' do + other_project = create(:project, namespace: parent) + other_subgroup_project = create(:project, namespace: subgroup) + + elements = [other_project, subsub_group, other_subgroup_project] + + expected_hierarchy = { parent => [other_project, { subgroup => [subsub_group, other_subgroup_project] }] } + + expect(described_class.merge_hierarchies(elements)).to eq(expected_hierarchy) + end + + it 'combines upto a given parent' do + other_project = create(:project, namespace: parent) + other_subgroup_project = create(:project, namespace: subgroup) + + elements = [other_project, subsub_group, other_subgroup_project] + + expected_hierarchy = [other_project, { subgroup => [subsub_group, other_subgroup_project] }] + + expect(described_class.merge_hierarchies(elements, parent)).to eq(expected_hierarchy) + end + end end end diff --git a/spec/serializers/group_child_serializer_spec.rb b/spec/serializers/group_child_serializer_spec.rb new file mode 100644 index 00000000000..967ed06d316 --- /dev/null +++ b/spec/serializers/group_child_serializer_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe GroupChildSerializer do + let(:request) { double('request') } + let(:user) { create(:user) } + subject(:serializer) { described_class.new(current_user: user) } + + describe '#represent' do + context 'for groups' do + it 'can render a single group' do + expect(serializer.represent(build(:group))).to be_kind_of(Hash) + end + + it 'can render a collection of groups' do + expect(serializer.represent(build_list(:group, 2))).to be_kind_of(Array) + end + end + + context 'with a hierarchy' do + let(:parent) { create(:group) } + + subject(:serializer) do + described_class.new(current_user: user).expand_hierarchy(parent) + end + + it 'expands the subgroups' do + subgroup = create(:group, parent: parent) + subsub_group = create(:group, parent: subgroup) + + json = serializer.represent(subsub_group) + subsub_group_json = json[:children].first + + expect(json[:id]).to eq(subgroup.id) + expect(subsub_group_json).not_to be_nil + expect(subsub_group_json[:id]).to eq(subsub_group.id) + end + + it 'can expand multiple trees' do + + end + end + end +end |