debian-mirror-gitlab/spec/factories/groups.rb

96 lines
2.5 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
FactoryBot.define do
2020-03-13 15:44:24 +05:30
factory :group, class: 'Group', parent: :namespace do
2016-06-02 11:05:42 +05:30
sequence(:name) { |n| "group#{n}" }
path { name.downcase.gsub(/\s/, '_') }
2019-12-21 20:55:43 +05:30
type { 'Group' }
owner { nil }
2020-05-24 23:13:21 +05:30
project_creation_level { ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS }
2016-06-02 11:05:42 +05:30
2018-10-15 14:42:47 +05:30
after(:create) do |group|
if group.owner
# We could remove this after we have proper constraint:
2019-12-04 20:38:33 +05:30
# https://gitlab.com/gitlab-org/gitlab-foss/issues/43292
2018-10-15 14:42:47 +05:30
raise "Don't set owner for groups, use `group.add_owner(user)` instead"
end
2021-01-03 14:25:43 +05:30
2021-04-17 20:07:23 +05:30
create(:namespace_settings, namespace: group) unless group.namespace_settings
2018-10-15 14:42:47 +05:30
end
2016-06-02 11:05:42 +05:30
trait :public do
2020-05-24 23:13:21 +05:30
visibility_level { Gitlab::VisibilityLevel::PUBLIC }
2016-06-02 11:05:42 +05:30
end
trait :internal do
2021-01-03 14:25:43 +05:30
visibility_level { Gitlab::VisibilityLevel::INTERNAL }
2016-06-02 11:05:42 +05:30
end
trait :private do
2020-05-24 23:13:21 +05:30
visibility_level { Gitlab::VisibilityLevel::PRIVATE }
2016-06-02 11:05:42 +05:30
end
2017-08-17 22:00:37 +05:30
trait :with_avatar do
2018-03-17 18:26:18 +05:30
avatar { fixture_file_upload('spec/fixtures/dk.png') }
2017-08-17 22:00:37 +05:30
end
2019-12-21 20:55:43 +05:30
trait :request_access_disabled do
request_access_enabled { false }
2017-08-17 22:00:37 +05:30
end
trait :nested do
parent factory: :group
end
2019-07-07 11:18:12 +05:30
trait :auto_devops_enabled do
2019-12-21 20:55:43 +05:30
auto_devops_enabled { true }
2019-07-07 11:18:12 +05:30
end
trait :auto_devops_disabled do
2019-12-21 20:55:43 +05:30
auto_devops_enabled { false }
2019-07-07 11:18:12 +05:30
end
2019-10-12 21:52:04 +05:30
trait :owner_subgroup_creation_only do
2020-05-24 23:13:21 +05:30
subgroup_creation_level { ::Gitlab::Access::OWNER_SUBGROUP_ACCESS }
2019-10-12 21:52:04 +05:30
end
2020-07-28 23:09:34 +05:30
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
2021-04-17 20:07:23 +05:30
# 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
2016-06-02 11:05:42 +05:30
end
end