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 :protected_branch do
|
|
|
|
name
|
|
|
|
project
|
2016-07-08 02:15:02 -04:00
|
|
|
|
2017-07-27 09:45:17 -04:00
|
|
|
transient do
|
|
|
|
default_push_level true
|
|
|
|
default_merge_level true
|
|
|
|
default_access_level true
|
2016-07-08 02:15:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :developers_can_push do
|
2017-07-27 09:45:17 -04:00
|
|
|
transient do
|
|
|
|
default_push_level false
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
|
|
|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::DEVELOPER)
|
2016-07-29 02:13:07 -04:00
|
|
|
end
|
2016-07-08 02:15:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :developers_can_merge do
|
2017-07-27 09:45:17 -04:00
|
|
|
transient do
|
|
|
|
default_merge_level false
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
|
|
|
protected_branch.merge_access_levels.new(access_level: Gitlab::Access::DEVELOPER)
|
2016-07-29 02:13:07 -04:00
|
|
|
end
|
2016-07-08 02:15:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :no_one_can_push do
|
2017-07-27 09:45:17 -04:00
|
|
|
transient do
|
|
|
|
default_push_level false
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
|
|
|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::NO_ACCESS)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
trait :maintainers_can_push do
|
2017-07-27 09:45:17 -04:00
|
|
|
transient do
|
|
|
|
default_push_level false
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
2018-07-11 10:36:08 -04:00
|
|
|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
|
2017-07-27 09:45:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch, evaluator|
|
|
|
|
if evaluator.default_access_level && evaluator.default_push_level
|
2018-07-11 10:36:08 -04:00
|
|
|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
|
2017-07-27 09:45:17 -04:00
|
|
|
end
|
2018-01-11 11:34:01 -05:00
|
|
|
|
2017-07-27 09:45:17 -04:00
|
|
|
if evaluator.default_access_level && evaluator.default_merge_level
|
2018-07-11 10:36:08 -04:00
|
|
|
protected_branch.merge_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
|
2016-07-29 02:13:07 -04:00
|
|
|
end
|
2016-07-08 02:15:02 -04:00
|
|
|
end
|
2017-08-02 06:16:17 -04:00
|
|
|
|
|
|
|
trait :no_one_can_merge do
|
|
|
|
after(:create) do |protected_branch|
|
|
|
|
protected_branch.merge_access_levels.first.update!(access_level: Gitlab::Access::NO_ACCESS)
|
|
|
|
end
|
|
|
|
end
|
2016-02-16 22:55:24 -05:00
|
|
|
end
|
|
|
|
end
|