diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-09-19 13:11:09 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-04 22:49:41 +0200 |
commit | 22aa034427b9392b44d9ecba0a51bb1b6c6616d7 (patch) | |
tree | 674a46d4ea73af07ccc3b7f5dd56168d4c5c1997 /spec/finders/group_descendants_finder_spec.rb | |
parent | fb7a0f8c335631e1cb8c8f91e135e49528fad70e (diff) | |
download | gitlab-ce-22aa034427b9392b44d9ecba0a51bb1b6c6616d7.tar.gz |
Rename `GroupHierarchy` to `GroupDescendant`
Diffstat (limited to 'spec/finders/group_descendants_finder_spec.rb')
-rw-r--r-- | spec/finders/group_descendants_finder_spec.rb | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/spec/finders/group_descendants_finder_spec.rb b/spec/finders/group_descendants_finder_spec.rb new file mode 100644 index 00000000000..c1268a486cf --- /dev/null +++ b/spec/finders/group_descendants_finder_spec.rb @@ -0,0 +1,93 @@ +require 'spec_helper' + +describe GroupDescendantsFinder do + let(:user) { create(:user) } + let(:group) { create(:group) } + let(:params) { {} } + subject(:finder) do + described_class.new(current_user: user, parent_group: group, params: params) + end + + before do + group.add_owner(user) + end + + describe '#execute' do + it 'includes projects' do + project = create(:project, namespace: group) + + expect(finder.execute).to contain_exactly(project) + end + + context 'with a filter' do + let(:params) { { filter: 'test' } } + + it 'includes only projects matching the filter' do + _other_project = create(:project, namespace: group) + matching_project = create(:project, namespace: group, name: 'testproject') + + expect(finder.execute).to contain_exactly(matching_project) + end + end + end + + context 'with nested groups', :nested_groups do + let!(:project) { create(:project, namespace: group) } + let!(:subgroup) { create(:group, parent: group) } + + describe '#execute' do + it 'contains projects and subgroups' do + expect(finder.execute).to contain_exactly(subgroup, project) + end + + context 'with a filter' do + let(:params) { { filter: 'test' } } + + it 'contains only matching projects and subgroups' do + matching_project = create(:project, namespace: group, name: 'Testproject') + matching_subgroup = create(:group, name: 'testgroup', parent: group) + + expect(finder.execute).to contain_exactly(matching_subgroup, matching_project) + end + + context 'with matching children' do + it 'includes a group that has a subgroup matching the query' do + matching_subgroup = create(:group, name: 'testgroup', parent: subgroup) + + expect(finder.execute).to contain_exactly(matching_subgroup) + end + + it 'includes a group that has a project matching the query' do + matching_project = create(:project, namespace: subgroup, name: 'Testproject') + + 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 + + describe '#total_count' do + it 'counts the array children were already loaded' do + finder.instance_variable_set(:@children, [build(:project)]) + + expect(finder).not_to receive(:subgroups) + expect(finder).not_to receive(:projects) + + expect(finder.total_count).to eq(1) + end + + it 'performs a count without loading children when they are not loaded yet' do + expect(finder).to receive(:subgroups).and_call_original + expect(finder).to receive(:projects).and_call_original + + expect(finder.total_count).to eq(2) + end + end + end +end |