2019-03-30 07:23:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-05 08:32:52 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe LoadedInGroupList do
|
|
|
|
let(:parent) { create(:group) }
|
2019-12-19 00:08:01 +00:00
|
|
|
|
2017-10-05 08:32:52 +00:00
|
|
|
subject(:found_group) { Group.with_selects_for_list.find_by(id: parent.id) }
|
|
|
|
|
|
|
|
describe '.with_selects_for_list' do
|
|
|
|
it 'includes the preloaded counts for groups' do
|
2017-10-11 08:17:24 +00:00
|
|
|
create(:group, parent: parent)
|
|
|
|
create(:project, namespace: parent)
|
|
|
|
parent.add_developer(create(:user))
|
|
|
|
|
2017-10-05 08:32:52 +00:00
|
|
|
found_group = Group.with_selects_for_list.find_by(id: parent.id)
|
|
|
|
|
|
|
|
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
|
2017-10-11 08:17:24 +00:00
|
|
|
|
|
|
|
context 'with archived projects' do
|
|
|
|
it 'counts including archived projects when `true` is passed' do
|
|
|
|
create(:project, namespace: parent, archived: true)
|
|
|
|
create(:project, namespace: parent)
|
|
|
|
|
2017-10-11 15:05:39 +00:00
|
|
|
found_group = Group.with_selects_for_list(archived: 'true').find_by(id: parent.id)
|
2017-10-11 08:17:24 +00:00
|
|
|
|
|
|
|
expect(found_group.preloaded_project_count).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'counts only archived projects when `only` is passed' do
|
|
|
|
create_list(:project, 2, namespace: parent, archived: true)
|
|
|
|
create(:project, namespace: parent)
|
|
|
|
|
2017-10-11 15:05:39 +00:00
|
|
|
found_group = Group.with_selects_for_list(archived: 'only').find_by(id: parent.id)
|
2017-10-11 08:17:24 +00:00
|
|
|
|
|
|
|
expect(found_group.preloaded_project_count).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
2017-10-05 08:32:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#children_count' do
|
|
|
|
it 'counts groups and projects' do
|
2017-10-11 08:17:24 +00:00
|
|
|
create(:group, parent: parent)
|
|
|
|
create(:project, namespace: parent)
|
|
|
|
|
2017-10-05 08:32:52 +00:00
|
|
|
expect(found_group.children_count).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|