summaryrefslogtreecommitdiff
path: root/spec/factories/groups.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/factories/groups.rb')
-rw-r--r--spec/factories/groups.rb32
1 files changed, 31 insertions, 1 deletions
diff --git a/spec/factories/groups.rb b/spec/factories/groups.rb
index 17db69e4699..5d232a9d09a 100644
--- a/spec/factories/groups.rb
+++ b/spec/factories/groups.rb
@@ -15,7 +15,7 @@ FactoryBot.define do
raise "Don't set owner for groups, use `group.add_owner(user)` instead"
end
- create(:namespace_settings, namespace: group)
+ create(:namespace_settings, namespace: group) unless group.namespace_settings
end
trait :public do
@@ -61,5 +61,35 @@ FactoryBot.define do
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