2019-07-25 01:11:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-13 19:13:44 -05:00
|
|
|
FactoryBot.define do
|
2016-02-16 22:55:24 -05:00
|
|
|
factory :namespace do
|
|
|
|
sequence(:name) { |n| "namespace#{n}" }
|
|
|
|
path { name.downcase.gsub(/\s/, '_') }
|
2018-04-23 11:48:26 -04:00
|
|
|
|
|
|
|
# This is a workaround to avoid the user creating another namespace via
|
|
|
|
# User#ensure_namespace_correct. We should try to remove it and then
|
|
|
|
# we could remove this workaround
|
|
|
|
association :owner, factory: :user, strategy: :build
|
|
|
|
before(:create) do |namespace|
|
|
|
|
owner = namespace.owner
|
|
|
|
|
|
|
|
if owner
|
|
|
|
# We're changing the username here because we want to keep our path,
|
|
|
|
# and User#ensure_namespace_correct would change the path based on
|
|
|
|
# username, so we're forced to do this otherwise we'll need to change
|
|
|
|
# a lot of existing tests.
|
|
|
|
owner.username = namespace.path
|
|
|
|
owner.namespace = namespace
|
|
|
|
end
|
|
|
|
end
|
2019-06-12 17:11:14 -04:00
|
|
|
|
|
|
|
trait :with_aggregation_schedule do
|
|
|
|
association :aggregation_schedule, factory: :namespace_aggregation_schedules
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_root_storage_statistics do
|
|
|
|
association :root_storage_statistics, factory: :namespace_root_storage_statistics
|
|
|
|
end
|
2020-07-14 05:09:02 -04:00
|
|
|
|
2020-08-04 11:09:27 -04:00
|
|
|
trait :with_namespace_settings do
|
|
|
|
association :namespace_settings, factory: :namespace_settings
|
|
|
|
end
|
|
|
|
|
2020-07-14 05:09:02 -04:00
|
|
|
# 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
|
2020-09-30 11:09:46 -04:00
|
|
|
|
|
|
|
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
|
2016-02-16 22:55:24 -05:00
|
|
|
end
|
|
|
|
end
|