gitlab-org--gitlab-foss/spec/factories/protected_branches.rb
Timothy Andrew 37651d2f4c Fix the protected branches factory.
1. Previously, we were using `after_create` to create access levels.

2. At the time of protected branch creation, there are _no_ access
   levels present, which is invalid, and creation fails.

3. Fixed by setting access levels before the protected branch is created.
2016-08-16 12:45:48 +05:30

29 lines
887 B
Ruby

FactoryGirl.define do
factory :protected_branch do
name
project
before(:create) do |protected_branch|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::MASTER)
protected_branch.merge_access_levels.new(access_level: Gitlab::Access::MASTER)
end
trait :developers_can_push do
after(:create) do |protected_branch|
protected_branch.push_access_levels.first.update!(access_level: Gitlab::Access::DEVELOPER)
end
end
trait :developers_can_merge do
after(:create) do |protected_branch|
protected_branch.merge_access_levels.first.update!(access_level: Gitlab::Access::DEVELOPER)
end
end
trait :no_one_can_push do
after(:create) do |protected_branch|
protected_branch.push_access_levels.first.update!(access_level: Gitlab::Access::NO_ACCESS)
end
end
end
end