gitlab-org--gitlab-foss/spec/factories/projects.rb

210 lines
6.8 KiB
Ruby
Raw Normal View History

FactoryGirl.define do
# Project without repository
#
# Project does not have bare repository.
2016-07-05 18:24:35 -04:00
# Use this factory if you don't need repository in tests
factory :empty_project, class: 'Project' do
sequence(:name) { |n| "project#{n}" }
path { name.downcase.gsub(/\s/, '_') }
namespace
creator
# Behaves differently to nil due to cache_has_external_issue_tracker
has_external_issue_tracker false
trait :public do
visibility_level Gitlab::VisibilityLevel::PUBLIC
end
trait :internal do
visibility_level Gitlab::VisibilityLevel::INTERNAL
end
trait :private do
visibility_level Gitlab::VisibilityLevel::PRIVATE
end
trait :archived do
archived true
end
trait :access_requestable do
request_access_enabled true
end
trait :repository do
# no-op... for now!
end
trait :empty_repo do
after(:create) do |project|
raise "Failed to create repository!" unless project.create_repository
# We delete hooks so that gitlab-shell will not try to authenticate with
# an API that isn't running
FileUtils.rm_r(File.join(project.repository_storage_path, "#{project.path_with_namespace}.git", 'hooks'))
end
end
2016-08-01 18:31:21 -04:00
trait :broken_repo do
after(:create) do |project|
raise "Failed to create repository!" unless project.create_repository
FileUtils.rm_r(File.join(project.repository_storage_path, "#{project.path_with_namespace}.git", 'refs'))
end
end
2016-12-14 19:59:04 -05:00
trait :test_repo do
after :create do |project|
TestEnv.copy_repo(project)
end
end
trait(:wiki_enabled) { wiki_access_level ProjectFeature::ENABLED }
trait(:wiki_disabled) { wiki_access_level ProjectFeature::DISABLED }
trait(:wiki_private) { wiki_access_level ProjectFeature::PRIVATE }
trait(:builds_enabled) { builds_access_level ProjectFeature::ENABLED }
trait(:builds_disabled) { builds_access_level ProjectFeature::DISABLED }
trait(:builds_private) { builds_access_level ProjectFeature::PRIVATE }
trait(:snippets_enabled) { snippets_access_level ProjectFeature::ENABLED }
trait(:snippets_disabled) { snippets_access_level ProjectFeature::DISABLED }
trait(:snippets_private) { snippets_access_level ProjectFeature::PRIVATE }
trait(:issues_disabled) { issues_access_level ProjectFeature::DISABLED }
trait(:issues_enabled) { issues_access_level ProjectFeature::ENABLED }
trait(:issues_private) { issues_access_level ProjectFeature::PRIVATE }
trait(:merge_requests_enabled) { merge_requests_access_level ProjectFeature::ENABLED }
trait(:merge_requests_disabled) { merge_requests_access_level ProjectFeature::DISABLED }
trait(:merge_requests_private) { merge_requests_access_level ProjectFeature::PRIVATE }
trait(:repository_enabled) { repository_access_level ProjectFeature::ENABLED }
trait(:repository_disabled) { repository_access_level ProjectFeature::DISABLED }
trait(:repository_private) { repository_access_level ProjectFeature::PRIVATE }
2016-08-01 18:31:21 -04:00
# Nest Project Feature attributes
transient do
wiki_access_level ProjectFeature::ENABLED
builds_access_level ProjectFeature::ENABLED
snippets_access_level ProjectFeature::ENABLED
issues_access_level ProjectFeature::ENABLED
merge_requests_access_level ProjectFeature::ENABLED
repository_access_level ProjectFeature::ENABLED
2016-08-01 18:31:21 -04:00
end
after(:create) do |project, evaluator|
# Builds and MRs can't have higher visibility level than repository access level.
builds_access_level = [evaluator.builds_access_level, evaluator.repository_access_level].min
merge_requests_access_level = [evaluator.merge_requests_access_level, evaluator.repository_access_level].min
2016-08-01 18:31:21 -04:00
project.project_feature.
update_attributes!(
2016-08-01 18:31:21 -04:00
wiki_access_level: evaluator.wiki_access_level,
builds_access_level: builds_access_level,
2016-08-01 18:31:21 -04:00
snippets_access_level: evaluator.snippets_access_level,
issues_access_level: evaluator.issues_access_level,
merge_requests_access_level: merge_requests_access_level,
repository_access_level: evaluator.repository_access_level
2016-08-01 18:31:21 -04:00
)
end
end
# Project with empty repository
#
# This is a case when you just created a project
# but not pushed any code there yet
factory :project_empty_repo, parent: :empty_project do
empty_repo
end
# Project with broken repository
#
# Project with an invalid repository state
factory :project_broken_repo, parent: :empty_project do
broken_repo
end
# Project with test repository
#
# Test repository source can be found at
# https://gitlab.com/gitlab-org/gitlab-test
factory :project, parent: :empty_project do
path { 'gitlabhq' }
2016-12-14 19:59:04 -05:00
test_repo
2016-12-08 06:11:52 -05:00
transient do
create_template nil
end
after :create do |project, evaluator|
TestEnv.copy_repo(project)
2016-12-08 06:11:52 -05:00
if evaluator.create_template
args = evaluator.create_template
project.add_user(args[:user], args[:access])
project.repository.create_file(
2016-12-08 06:11:52 -05:00
args[:user],
".gitlab/#{args[:path]}/bug.md",
'something valid',
message: 'test 3',
branch_name: 'master')
project.repository.create_file(
2016-12-08 06:11:52 -05:00
args[:user],
".gitlab/#{args[:path]}/template_test.md",
'template_test',
message: 'test 1',
branch_name: 'master')
project.repository.create_file(
2016-12-08 06:11:52 -05:00
args[:user],
".gitlab/#{args[:path]}/feature_proposal.md",
'feature_proposal',
message: 'test 2',
branch_name: 'master')
2016-12-08 06:11:52 -05:00
end
end
end
factory :forked_project_with_submodules, parent: :empty_project do
path { 'forked-gitlabhq' }
after :create do |project|
TestEnv.copy_forked_repo_with_submodules(project)
end
end
factory :redmine_project, parent: :project do
has_external_issue_tracker true
after :create do |project|
project.create_redmine_service(
active: true,
properties: {
'project_url' => 'http://redmine/projects/project_name_in_redmine',
'issues_url' => "http://redmine/#{project.id}/project_name_in_redmine/:id",
'new_issue_url' => 'http://redmine/projects/project_name_in_redmine/issues/new'
}
)
end
end
2015-04-29 14:28:24 -04:00
factory :jira_project, parent: :project do
has_external_issue_tracker true
jira_service
2015-04-29 14:28:24 -04:00
end
factory :kubernetes_project, parent: :empty_project do
kubernetes_service
end
factory :prometheus_project, parent: :empty_project do
after :create do |project|
project.create_prometheus_service(
active: true,
properties: {
api_url: 'https://prometheus.example.com'
}
)
end
end
end