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 ...@@ -52,7 +52,7 @@ class GroupChildrenFinder
end end
def subgroups_matching_filter def subgroups_matching_filter
all_subgroups.search(params[:filter]).include(:parent) all_subgroups.search(params[:filter])
end end
def subgroups def subgroups
...@@ -64,7 +64,7 @@ class GroupChildrenFinder ...@@ -64,7 +64,7 @@ class GroupChildrenFinder
else else
base_groups base_groups
end end
groups = groups.includes(:route).includes(:children) groups = groups
groups.sort(params[:sort]) groups.sort(params[:sort])
end end
...@@ -75,7 +75,6 @@ class GroupChildrenFinder ...@@ -75,7 +75,6 @@ class GroupChildrenFinder
def projects_matching_filter def projects_matching_filter
ProjectsFinder.new(current_user: current_user).execute ProjectsFinder.new(current_user: current_user).execute
.search(params[:filter]) .search(params[:filter])
.include(:namespace)
.where(namespace: all_subgroups) .where(namespace: all_subgroups)
end end
...@@ -87,7 +86,6 @@ class GroupChildrenFinder ...@@ -87,7 +86,6 @@ class GroupChildrenFinder
else else
base_projects base_projects
end end
projects = projects.includes(:route)
projects.sort(params[:sort]) projects.sort(params[:sort])
end end
end end
...@@ -62,7 +62,12 @@ module GroupHierarchy ...@@ -62,7 +62,12 @@ module GroupHierarchy
# If both of them are hashes, we can deep_merge with the same logic # 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) elsif first_child.is_a?(Hash) && second_child.is_a?(Hash)
first_child.deep_merge(second_child) { |key, first, second| merge_values(first, second) } 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 else
Array.wrap(first_child) + Array.wrap(second_child) Array.wrap(first_child) + Array.wrap(second_child)
end end
......
...@@ -124,6 +124,12 @@ describe GroupHierarchy, :nested_groups do ...@@ -124,6 +124,12 @@ describe GroupHierarchy, :nested_groups do
expect(described_class.merge_hierarchies(elements, parent)).to eq(expected_hierarchy) expect(described_class.merge_hierarchies(elements, parent)).to eq(expected_hierarchy)
end 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 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