From 6388b8feec28b0f0ca2f9e6d9c5c7b4e404fed2f Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Sun, 10 Sep 2017 18:55:52 +0200 Subject: [PATCH] Don't include the parent in search results if it matches --- app/finders/group_children_finder.rb | 2 +- spec/finders/group_children_finder_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/finders/group_children_finder.rb b/app/finders/group_children_finder.rb index 07b97163c62..9760f9ef802 100644 --- a/app/finders/group_children_finder.rb +++ b/app/finders/group_children_finder.rb @@ -52,7 +52,7 @@ class GroupChildrenFinder end def subgroups_matching_filter - all_subgroups.search(params[:filter]) + all_subgroups.where.not(id: parent_group).search(params[:filter]) end def subgroups diff --git a/spec/finders/group_children_finder_spec.rb b/spec/finders/group_children_finder_spec.rb index 8f83f88bb97..3df153abc6a 100644 --- a/spec/finders/group_children_finder_spec.rb +++ b/spec/finders/group_children_finder_spec.rb @@ -60,6 +60,12 @@ describe GroupChildrenFinder do expect(finder.execute).to contain_exactly(matching_project) end + + it 'does not include the parent itself' do + group.update!(name: 'test') + + expect(finder.execute).not_to include(group) + end end end end