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

243 lines
7.9 KiB
Ruby
Raw Normal View History

2017-09-10 17:25:29 +05:30
require_relative '../support/test_env'
2014-09-02 18:07:02 +05:30
FactoryGirl.define do
2015-04-26 12:48:37 +05:30
# Project without repository
#
# Project does not have bare repository.
2016-08-24 12:49:21 +05:30
# Use this factory if you don't need repository in tests
2017-09-10 17:25:29 +05:30
factory :project, class: 'Project' do
2014-09-02 18:07:02 +05:30
sequence(:name) { |n| "project#{n}" }
path { name.downcase.gsub(/\s/, '_') }
namespace
creator
2016-11-03 12:29:30 +05:30
# Behaves differently to nil due to cache_has_external_issue_tracker
has_external_issue_tracker false
2014-09-02 18:07:02 +05:30
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
2016-06-02 11:05:42 +05:30
2017-09-10 17:25:29 +05:30
trait :import_scheduled do
import_status :scheduled
end
trait :import_started do
import_status :started
end
trait :import_finished do
import_status :finished
end
trait :import_failed do
import_status :failed
end
2017-08-17 22:00:37 +05:30
trait :archived do
archived true
end
trait :access_requestable do
request_access_enabled true
end
trait :with_avatar do
avatar { File.open(Rails.root.join('spec/fixtures/dk.png')) }
end
2017-09-10 17:25:29 +05:30
trait :broken_storage do
after(:create) do |project|
project.update_column(:repository_storage, 'broken')
end
end
# Test repository - https://gitlab.com/gitlab-org/gitlab-test
2017-08-17 22:00:37 +05:30
trait :repository do
2017-09-10 17:25:29 +05:30
test_repo
transient do
create_template nil
end
after :create do |project, evaluator|
if evaluator.create_template
args = evaluator.create_template
project.add_user(args[:user], args[:access])
project.repository.create_file(
args[:user],
".gitlab/#{args[:path]}/bug.md",
'something valid',
message: 'test 3',
branch_name: 'master')
project.repository.create_file(
args[:user],
".gitlab/#{args[:path]}/template_test.md",
'template_test',
message: 'test 1',
branch_name: 'master')
project.repository.create_file(
args[:user],
".gitlab/#{args[:path]}/feature_proposal.md",
'feature_proposal',
message: 'test 2',
branch_name: 'master')
end
end
2017-08-17 22:00:37 +05:30
end
2016-06-02 11:05:42 +05:30
trait :empty_repo do
after(:create) do |project|
2017-08-17 22:00:37 +05:30
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
2017-09-10 17:25:29 +05:30
FileUtils.rm_r(File.join(project.repository_storage_path, "#{project.disk_path}.git", 'hooks'))
2016-06-02 11:05:42 +05:30
end
end
2016-09-29 09:46:39 +05:30
2016-11-03 12:29:30 +05:30
trait :broken_repo do
after(:create) do |project|
2017-08-17 22:00:37 +05:30
raise "Failed to create repository!" unless project.create_repository
2016-11-03 12:29:30 +05:30
2017-09-10 17:25:29 +05:30
FileUtils.rm_r(File.join(project.repository_storage_path, "#{project.disk_path}.git", 'refs'))
2016-11-03 12:29:30 +05:30
end
end
2017-08-17 22:00:37 +05:30
trait :test_repo do
after :create do |project|
2017-09-10 17:25:29 +05:30
TestEnv.copy_repo(project,
bare_repo: TestEnv.factory_repo_path_bare,
refs: TestEnv::BRANCH_SHA)
2017-08-17 22:00:37 +05:30
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-09-29 09:46:39 +05:30
# 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
2016-11-03 12:29:30 +05:30
repository_access_level ProjectFeature::ENABLED
2016-09-29 09:46:39 +05:30
end
after(:create) do |project, evaluator|
2016-11-24 13:41:30 +05:30
# 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
2017-09-10 17:25:29 +05:30
project.project_feature
.update_attributes!(
2016-09-29 09:46:39 +05:30
wiki_access_level: evaluator.wiki_access_level,
2016-11-24 13:41:30 +05:30
builds_access_level: builds_access_level,
2016-09-29 09:46:39 +05:30
snippets_access_level: evaluator.snippets_access_level,
issues_access_level: evaluator.issues_access_level,
2016-11-24 13:41:30 +05:30
merge_requests_access_level: merge_requests_access_level,
2016-11-03 12:29:30 +05:30
repository_access_level: evaluator.repository_access_level
2016-09-29 09:46:39 +05:30
)
2017-09-10 17:25:29 +05:30
# Normally the class Projects::CreateService is used for creating
# projects, and this class takes care of making sure the owner and current
# user have access to the project. Our specs don't use said service class,
# thus we must manually refresh things here.
owner = project.owner
if owner && owner.is_a?(User) && !project.pending_delete
project.members.create!(user: owner, access_level: Gitlab::Access::MASTER)
end
project.group&.refresh_members_authorized_projects
2016-09-29 09:46:39 +05:30
end
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
# Project with empty repository
2014-09-02 18:07:02 +05:30
#
2015-04-26 12:48:37 +05:30
# This is a case when you just created a project
# but not pushed any code there yet
2017-09-10 17:25:29 +05:30
factory :project_empty_repo, parent: :project do
2016-06-02 11:05:42 +05:30
empty_repo
2015-04-26 12:48:37 +05:30
end
2016-11-03 12:29:30 +05:30
# Project with broken repository
#
# Project with an invalid repository state
2017-09-10 17:25:29 +05:30
factory :project_broken_repo, parent: :project do
2016-11-03 12:29:30 +05:30
broken_repo
end
2017-09-10 17:25:29 +05:30
factory :forked_project_with_submodules, parent: :project do
2015-09-11 14:41:01 +05:30
path { 'forked-gitlabhq' }
after :create do |project|
2017-09-10 17:25:29 +05:30
TestEnv.copy_repo(project,
bare_repo: TestEnv.forked_repo_path_bare,
refs: TestEnv::FORKED_BRANCH_SHA)
2015-09-11 14:41:01 +05:30
end
end
2014-09-02 18:07:02 +05:30
factory :redmine_project, parent: :project do
2016-11-03 12:29:30 +05:30
has_external_issue_tracker true
2015-04-26 12:48:37 +05:30
after :create do |project|
project.create_redmine_service(
active: true,
properties: {
'project_url' => 'http://redmine/projects/project_name_in_redmine',
2017-08-17 22:00:37 +05:30
'issues_url' => 'http://redmine/projects/project_name_in_redmine/issues/:id',
2015-04-26 12:48:37 +05:30
'new_issue_url' => 'http://redmine/projects/project_name_in_redmine/issues/new'
}
)
end
2014-09-02 18:07:02 +05:30
end
2015-09-11 14:41:01 +05:30
factory :jira_project, parent: :project do
2016-11-03 12:29:30 +05:30
has_external_issue_tracker true
2017-08-17 22:00:37 +05:30
jira_service
end
2017-09-10 17:25:29 +05:30
factory :kubernetes_project, parent: :project do
2017-08-17 22:00:37 +05:30
kubernetes_service
end
2016-11-03 12:29:30 +05:30
2017-09-10 17:25:29 +05:30
factory :prometheus_project, parent: :project do
2015-09-11 14:41:01 +05:30
after :create do |project|
2017-08-17 22:00:37 +05:30
project.create_prometheus_service(
2015-09-11 14:41:01 +05:30
active: true,
properties: {
2017-08-17 22:00:37 +05:30
api_url: 'https://prometheus.example.com'
2015-09-11 14:41:01 +05:30
}
)
end
end
2014-09-02 18:07:02 +05:30
end