Commit bb5187bb authored by Bob Van Landuyt's avatar Bob Van Landuyt

Handle case where 2 matches in the same tree are found

parent 8f6dac49
......@@ -52,7 +52,7 @@ class GroupChildrenFinder
end
def subgroups_matching_filter
all_subgroups.search(params[:filter]).include(:parent)
all_subgroups.search(params[:filter])
end
def subgroups
......@@ -64,7 +64,7 @@ class GroupChildrenFinder
else
base_groups
end
groups = groups.includes(:route).includes(:children)
groups = groups
groups.sort(params[:sort])
end
......@@ -75,7 +75,6 @@ class GroupChildrenFinder
def projects_matching_filter
ProjectsFinder.new(current_user: current_user).execute
.search(params[:filter])
.include(:namespace)
.where(namespace: all_subgroups)
end
......@@ -87,7 +86,6 @@ class GroupChildrenFinder
else
base_projects
end
projects = projects.includes(:route)
projects.sort(params[:sort])
end
end
......@@ -62,7 +62,12 @@ module GroupHierarchy
# If both of them are hashes, we can deep_merge with the same logic
elsif first_child.is_a?(Hash) && second_child.is_a?(Hash)
first_child.deep_merge(second_child) { |key, first, second| merge_values(first, second) }
# One of them is a root node, we just need to put them next to eachother in an array
# If only one of them is a hash, we can check if the other child is already
# included, we don't need to do anything when it is.
elsif first_child.is_a?(Hash) && first_child.keys.include?(second_child)
first_child
elsif second_child.is_a?(Hash) && second_child.keys.include?(first_child)
second_child
else
Array.wrap(first_child) + Array.wrap(second_child)
end
......
......@@ -124,6 +124,12 @@ describe GroupHierarchy, :nested_groups do
expect(described_class.merge_hierarchies(elements, parent)).to eq(expected_hierarchy)
end
it 'merges to elements in the same hierarchy' do
expected_hierarchy = { parent => subgroup }
expect(described_class.merge_hierarchies([parent, subgroup])).to eq(expected_hierarchy)
end
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