summaryrefslogtreecommitdiff
path: root/spec/factories/namespaces.rb
blob: 2b3dabc07d86af8e2cd0556f2e2a93d267f9f88d (plain)
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
# frozen_string_literal: true

FactoryBot.define do
  # 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
    sequence(:name) { |n| "namespace#{n}" }
    type { Namespaces::UserNamespace.sti_name }

    path { name.downcase.gsub(/\s/, '_') }

    owner { association(:user, strategy: :build, namespace: instance, username: path) }

    trait :with_aggregation_schedule do
      after(:create) do |namespace|
        create(:namespace_aggregation_schedules, namespace: namespace)
      end
    end

    trait :with_root_storage_statistics do
      after(:create) do |namespace|
        create(:namespace_root_storage_statistics, namespace: namespace)
      end
    end

    trait :with_namespace_settings do
      after(:create) do |namespace|
        create(:namespace_settings, namespace: namespace)
      end
    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
  end
end