2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe LoadedInGroupList do
|
2021-12-11 22:18:48 +05:30
|
|
|
let_it_be(:parent) { create(:group) }
|
|
|
|
let_it_be(:group) { create(:group, parent: parent) }
|
|
|
|
let_it_be(:project) { create(:project, namespace: parent) }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
let(:archived_parameter) { nil }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
before do
|
|
|
|
parent.add_developer(create(:user))
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
subject(:found_group) { Group.with_selects_for_list(archived: archived_parameter).find_by(id: parent.id) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
describe '.with_selects_for_list' do
|
|
|
|
it 'includes the preloaded counts for groups' do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(found_group.preloaded_project_count).to eq(1)
|
|
|
|
expect(found_group.preloaded_subgroup_count).to eq(1)
|
|
|
|
expect(found_group.preloaded_member_count).to eq(1)
|
|
|
|
end
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
context 'with project namespaces' do
|
|
|
|
let_it_be(:group1) { create(:group, parent: parent) }
|
|
|
|
let_it_be(:group2) { create(:group, parent: parent) }
|
|
|
|
let_it_be(:project_namespace) { project.project_namespace }
|
|
|
|
|
|
|
|
it 'does not include project_namespaces in the count of subgroups' do
|
|
|
|
expect(found_group.preloaded_subgroup_count).to eq(3)
|
|
|
|
expect(parent.subgroup_count).to eq(3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'with archived projects' do
|
2021-12-11 22:18:48 +05:30
|
|
|
let_it_be(:archived_project) { create(:project, namespace: parent, archived: true) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
let(:archived_parameter) { true }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it 'counts including archived projects when `true` is passed' do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(found_group.preloaded_project_count).to eq(2)
|
|
|
|
end
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
context 'when not counting archived projects' do
|
|
|
|
let(:archived_parameter) { false }
|
|
|
|
|
|
|
|
it 'counts projects without archived ones' do
|
|
|
|
expect(found_group.preloaded_project_count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with archived only' do
|
|
|
|
let_it_be(:archived_project2) { create(:project, namespace: parent, archived: true) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
let(:archived_parameter) { 'only' }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it 'counts only archived projects when `only` is passed' do
|
|
|
|
expect(found_group.preloaded_project_count).to eq(2)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#children_count' do
|
|
|
|
it 'counts groups and projects' do
|
|
|
|
expect(found_group.children_count).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|