diff options
Diffstat (limited to 'spec/factories/namespaces.rb')
-rw-r--r-- | spec/factories/namespaces.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/factories/namespaces.rb b/spec/factories/namespaces.rb index 09dbe16ef9e..f4d5848e878 100644 --- a/spec/factories/namespaces.rb +++ b/spec/factories/namespaces.rb @@ -29,5 +29,35 @@ FactoryBot.define do trait :with_root_storage_statistics do association :root_storage_statistics, factory: :namespace_root_storage_statistics end + + # Construct a hierarchy underneath the namespace. + # Each namespace 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 |namespace, 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: namespace, + children: evaluator.children, + depth: evaluator.depth + ) + end + end end end |