diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-01-20 14:35:48 +0100 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-01-22 17:02:04 +0100 |
commit | 26c4e47a0d0f860da3f00c37fa28d175bb17ccf1 (patch) | |
tree | 2f2fcf72bf8b249af55731c1c49628dbcce6902d /spec | |
parent | 2c3c5b35549185080296670cfe6710aa80f99944 (diff) | |
download | gitlab-ce-26c4e47a0d0f860da3f00c37fa28d175bb17ccf1.tar.gz |
Preload ancestors for subgroups matching filter
Otherwise we'd only preload the ancestors that would fit the
page. That way, when a search result was on the first page, but the
ancestor didn't fit the page anymore. We would not have the preloaded
ancestor when rendering the hierarchy.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/groups/children_controller_spec.rb | 24 | ||||
-rw-r--r-- | spec/finders/group_descendants_finder_spec.rb | 13 |
2 files changed, 36 insertions, 1 deletions
diff --git a/spec/controllers/groups/children_controller_spec.rb b/spec/controllers/groups/children_controller_spec.rb index cb1b460fc0e..22d3076c269 100644 --- a/spec/controllers/groups/children_controller_spec.rb +++ b/spec/controllers/groups/children_controller_spec.rb @@ -160,6 +160,30 @@ describe Groups::ChildrenController do expect(json_response).to eq([]) end + it 'succeeds if multiple pages contain matching subgroups' do + create(:group, parent: group, name: 'subgroup-filter-1') + create(:group, parent: group, name: 'subgroup-filter-2') + + # Creating the group-to-nest first so it would be loaded into the + # relation first before it's parents, this is what would cause the + # crash in: https://gitlab.com/gitlab-org/gitlab-ce/issues/40785. + # + # If we create the parent groups first, those would be loaded into the + # collection first, and the pagination would cut off the actual search + # result. In this case the hierarchy can be rendered without crashing, + # it's just incomplete. + group_to_nest = create(:group, parent: group, name: 'subsubgroup-filter-3') + subgroup = create(:group, parent: group) + 3.times do |i| + subgroup = create(:group, parent: subgroup) + end + group_to_nest.update!(parent: subgroup) + + get :index, group_id: group.to_param, filter: 'filter', per_page: 3, format: :json + + expect(response).to have_gitlab_http_status(200) + end + it 'includes pagination headers' do 2.times { |i| create(:group, :public, parent: public_subgroup, name: "filterme#{i}") } diff --git a/spec/finders/group_descendants_finder_spec.rb b/spec/finders/group_descendants_finder_spec.rb index 9cadd9a6000..375bcc9087e 100644 --- a/spec/finders/group_descendants_finder_spec.rb +++ b/spec/finders/group_descendants_finder_spec.rb @@ -73,7 +73,7 @@ describe GroupDescendantsFinder do end context 'with a filter' do - let(:params) { { filter: 'tes' } } + let(:params) { { filter: 'test' } } it 'includes only projects matching the filter' do _other_project = create(:project, namespace: group) @@ -198,6 +198,17 @@ describe GroupDescendantsFinder do expect(finder.execute).to contain_exactly(subgroup, matching_project) end + context 'with a small page size' do + let(:params) { { filter: 'test', per_page: 1 } } + + it 'contains all the ancestors of a matching subgroup regardless the page size' do + subgroup = create(:group, :private, parent: group) + matching = create(:group, :private, name: 'testgroup', parent: subgroup) + + expect(finder.execute).to contain_exactly(subgroup, matching) + end + end + it 'does not include the parent itself' do group.update!(name: 'test') |