2019-07-25 01:11:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-13 19:13:44 -05:00
|
|
|
FactoryBot.define do
|
2021-11-26 07:12:49 -05:00
|
|
|
# This factory is called :namespace but actually maps (and always has) to User type
|
|
|
|
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74152#note_730034103 for context
|
|
|
|
factory :namespace, class: 'Namespaces::UserNamespace' do
|
2016-02-16 22:55:24 -05:00
|
|
|
sequence(:name) { |n| "namespace#{n}" }
|
2021-11-26 07:12:49 -05:00
|
|
|
type { Namespaces::UserNamespace.sti_name }
|
|
|
|
|
2016-02-16 22:55:24 -05:00
|
|
|
path { name.downcase.gsub(/\s/, '_') }
|
2018-04-23 11:48:26 -04:00
|
|
|
|
2021-04-20 20:11:06 -04:00
|
|
|
owner { association(:user, strategy: :build, namespace: instance, username: path) }
|
2019-06-12 17:11:14 -04:00
|
|
|
|
2021-12-31 13:16:55 -05:00
|
|
|
after(:create) do |namespace, evaluator|
|
|
|
|
# simulating ::Namespaces::ProcessSyncEventsWorker because most tests don't run Sidekiq inline
|
|
|
|
# Note: we need to get refreshed `traversal_ids` it is updated via SQL query
|
|
|
|
# in `Namespaces::Traversal::Linear#sync_traversal_ids` (see the NOTE in that method).
|
|
|
|
# We cannot use `.reload` because it cleans other on-the-fly attributes.
|
|
|
|
namespace.create_ci_namespace_mirror!(traversal_ids: Namespace.find(namespace.id).traversal_ids) unless namespace.ci_namespace_mirror
|
|
|
|
end
|
|
|
|
|
2019-06-12 17:11:14 -04:00
|
|
|
trait :with_aggregation_schedule do
|
2021-03-01 16:11:09 -05:00
|
|
|
after(:create) do |namespace|
|
|
|
|
create(:namespace_aggregation_schedules, namespace: namespace)
|
|
|
|
end
|
2019-06-12 17:11:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_root_storage_statistics do
|
2021-03-01 16:11:09 -05:00
|
|
|
after(:create) do |namespace|
|
|
|
|
create(:namespace_root_storage_statistics, namespace: namespace)
|
|
|
|
end
|
2019-06-12 17:11:14 -04:00
|
|
|
end
|
2020-07-14 05:09:02 -04:00
|
|
|
|
2020-08-04 11:09:27 -04:00
|
|
|
trait :with_namespace_settings do
|
2021-03-01 16:11:09 -05:00
|
|
|
after(:create) do |namespace|
|
|
|
|
create(:namespace_settings, namespace: namespace)
|
|
|
|
end
|
2020-08-04 11:09:27 -04:00
|
|
|
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
|