2019-07-25 01:11:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-13 19:13:44 -05:00
|
|
|
FactoryBot.define do
|
2020-01-09 13:07:52 -05:00
|
|
|
factory :group, class: 'Group', parent: :namespace do
|
2016-02-16 22:55:24 -05:00
|
|
|
sequence(:name) { |n| "group#{n}" }
|
|
|
|
path { name.downcase.gsub(/\s/, '_') }
|
2021-09-22 08:12:04 -04:00
|
|
|
type { Group.sti_name }
|
2019-10-01 20:06:26 -04:00
|
|
|
owner { nil }
|
2020-05-07 08:09:46 -04:00
|
|
|
project_creation_level { ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS }
|
2016-03-18 08:28:16 -04:00
|
|
|
|
2018-04-23 11:48:26 -04:00
|
|
|
after(:create) do |group|
|
|
|
|
if group.owner
|
|
|
|
# We could remove this after we have proper constraint:
|
2019-09-18 10:02:45 -04:00
|
|
|
# https://gitlab.com/gitlab-org/gitlab-foss/issues/43292
|
2018-04-23 11:48:26 -04:00
|
|
|
raise "Don't set owner for groups, use `group.add_owner(user)` instead"
|
|
|
|
end
|
2020-10-05 11:08:56 -04:00
|
|
|
|
2021-02-23 16:10:44 -05:00
|
|
|
create(:namespace_settings, namespace: group) unless group.namespace_settings
|
2018-04-23 11:48:26 -04:00
|
|
|
end
|
|
|
|
|
2016-03-18 08:28:16 -04:00
|
|
|
trait :public do
|
2020-05-07 08:09:46 -04:00
|
|
|
visibility_level { Gitlab::VisibilityLevel::PUBLIC }
|
2016-03-18 08:28:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :internal do
|
2020-10-15 08:09:06 -04:00
|
|
|
visibility_level { Gitlab::VisibilityLevel::INTERNAL }
|
2016-03-18 08:28:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :private do
|
2020-05-07 08:09:46 -04:00
|
|
|
visibility_level { Gitlab::VisibilityLevel::PRIVATE }
|
2016-03-18 08:28:16 -04:00
|
|
|
end
|
2016-11-11 07:51:50 -05:00
|
|
|
|
2017-05-03 11:25:31 -04:00
|
|
|
trait :with_avatar do
|
2018-02-01 14:24:59 -05:00
|
|
|
avatar { fixture_file_upload('spec/fixtures/dk.png') }
|
2017-05-03 11:25:31 -04:00
|
|
|
end
|
|
|
|
|
2019-10-16 08:06:32 -04:00
|
|
|
trait :request_access_disabled do
|
|
|
|
request_access_enabled { false }
|
2016-11-11 07:51:50 -05:00
|
|
|
end
|
2016-12-07 12:16:17 -05:00
|
|
|
|
|
|
|
trait :nested do
|
|
|
|
parent factory: :group
|
|
|
|
end
|
2019-03-12 06:15:33 -04:00
|
|
|
|
|
|
|
trait :auto_devops_enabled do
|
2019-10-01 20:06:26 -04:00
|
|
|
auto_devops_enabled { true }
|
2019-03-12 06:15:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :auto_devops_disabled do
|
2019-10-01 20:06:26 -04:00
|
|
|
auto_devops_enabled { false }
|
2019-03-12 06:15:33 -04:00
|
|
|
end
|
2019-06-30 17:40:23 -04:00
|
|
|
|
|
|
|
trait :owner_subgroup_creation_only do
|
2020-05-07 08:09:46 -04:00
|
|
|
subgroup_creation_level { ::Gitlab::Access::OWNER_SUBGROUP_ACCESS }
|
2019-06-30 17:40:23 -04:00
|
|
|
end
|
2020-07-06 05:09:20 -04:00
|
|
|
|
|
|
|
trait :shared_runners_disabled do
|
|
|
|
shared_runners_enabled { false }
|
|
|
|
end
|
|
|
|
|
2021-06-15 02:10:17 -04:00
|
|
|
trait :with_export do
|
|
|
|
after(:create) do |group, _evaluator|
|
|
|
|
export_file = fixture_file_upload('spec/fixtures/group_export.tar.gz')
|
|
|
|
create(:import_export_upload, group: group, export_file: export_file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-06 05:09:20 -04:00
|
|
|
trait :allow_descendants_override_disabled_shared_runners do
|
|
|
|
allow_descendants_override_disabled_shared_runners { true }
|
|
|
|
end
|
2021-03-01 10:10:53 -05:00
|
|
|
|
2021-10-13 11:12:51 -04:00
|
|
|
trait :disabled_and_unoverridable do
|
|
|
|
shared_runners_disabled
|
|
|
|
allow_descendants_override_disabled_shared_runners { false }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :disabled_with_override do
|
|
|
|
shared_runners_disabled
|
|
|
|
allow_descendants_override_disabled_shared_runners
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :shared_runners_enabled do
|
|
|
|
shared_runners_enabled { true }
|
|
|
|
end
|
|
|
|
|
2021-03-01 10:10:53 -05:00
|
|
|
# Construct a hierarchy underneath the group.
|
|
|
|
# Each group will have `children` amount of children,
|
|
|
|
# and `depth` levels of descendants.
|
|
|
|
trait :with_hierarchy do
|
|
|
|
transient do
|
|
|
|
children { 4 }
|
|
|
|
depth { 4 }
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:create) do |group, evaluator|
|
|
|
|
def create_graph(parent: nil, children: 4, depth: 4)
|
|
|
|
return unless depth > 1
|
|
|
|
|
|
|
|
children.times do
|
|
|
|
factory_name = parent.model_name.singular
|
|
|
|
child = FactoryBot.create(factory_name, parent: parent)
|
|
|
|
create_graph(parent: child, children: children, depth: depth - 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
parent
|
|
|
|
end
|
|
|
|
|
|
|
|
create_graph(
|
|
|
|
parent: group,
|
|
|
|
children: evaluator.children,
|
|
|
|
depth: evaluator.depth
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2022-01-07 19:14:32 -05:00
|
|
|
|
|
|
|
trait :crm_enabled do
|
|
|
|
after(:create) do |group|
|
|
|
|
create(:crm_settings, group: group, enabled: true)
|
|
|
|
end
|
|
|
|
end
|
2016-02-16 22:55:24 -05:00
|
|
|
end
|
|
|
|
end
|