1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# frozen_string_literal: true
FactoryBot.define do
factory :group, class: 'Group', parent: :namespace do
sequence(:name) { |n| "group#{n}" }
path { name.downcase.gsub(/\s/, '_') }
type { 'Group' }
owner { nil }
project_creation_level { ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS }
after(:create) do |group|
if group.owner
# We could remove this after we have proper constraint:
# https://gitlab.com/gitlab-org/gitlab-foss/issues/43292
raise "Don't set owner for groups, use `group.add_owner(user)` instead"
end
create(:namespace_settings, namespace: group) unless group.namespace_settings
end
trait :public do
visibility_level { Gitlab::VisibilityLevel::PUBLIC }
end
trait :internal do
visibility_level { Gitlab::VisibilityLevel::INTERNAL }
end
trait :private do
visibility_level { Gitlab::VisibilityLevel::PRIVATE }
end
trait :with_avatar do
avatar { fixture_file_upload('spec/fixtures/dk.png') }
end
trait :request_access_disabled do
request_access_enabled { false }
end
trait :nested do
parent factory: :group
end
trait :auto_devops_enabled do
auto_devops_enabled { true }
end
trait :auto_devops_disabled do
auto_devops_enabled { false }
end
trait :owner_subgroup_creation_only do
subgroup_creation_level { ::Gitlab::Access::OWNER_SUBGROUP_ACCESS }
end
trait :shared_runners_disabled do
shared_runners_enabled { false }
end
trait :allow_descendants_override_disabled_shared_runners do
allow_descendants_override_disabled_shared_runners { true }
end
# 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
end
end
|