2018-03-29 09:47:54 +00:00
|
|
|
require_relative '../support/helpers/test_env'
|
2017-05-31 13:43:19 +00:00
|
|
|
|
2017-12-14 00:13:44 +00:00
|
|
|
FactoryBot.define do
|
2019-02-01 07:51:33 +00:00
|
|
|
PAGES_ACCESS_LEVEL_SCHEMA_VERSION ||= 20180423204600
|
2018-10-05 13:41:11 +00:00
|
|
|
|
2014-11-30 08:50:15 +00:00
|
|
|
# Project without repository
|
|
|
|
#
|
|
|
|
# Project does not have bare repository.
|
2016-07-05 22:24:35 +00:00
|
|
|
# Use this factory if you don't need repository in tests
|
2017-08-02 19:43:24 +00:00
|
|
|
factory :project, class: 'Project' do
|
2014-07-31 17:13:27 +00:00
|
|
|
sequence(:name) { |n| "project#{n}" }
|
|
|
|
path { name.downcase.gsub(/\s/, '_') }
|
2016-10-06 21:17:11 +00:00
|
|
|
# Behaves differently to nil due to cache_has_external_issue_tracker
|
|
|
|
has_external_issue_tracker false
|
|
|
|
|
2017-08-09 09:31:25 +00:00
|
|
|
# Associations
|
|
|
|
namespace
|
|
|
|
creator { group ? create(:user) : namespace&.owner }
|
|
|
|
|
|
|
|
transient do
|
2017-11-08 12:08:13 +00:00
|
|
|
# Nest Project Feature attributes
|
2017-08-09 09:31:25 +00:00
|
|
|
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
|
2018-10-05 13:41:11 +00:00
|
|
|
pages_access_level ProjectFeature::ENABLED
|
2018-05-03 13:38:55 +00:00
|
|
|
|
|
|
|
# we can't assign the delegated `#ci_cd_settings` attributes directly, as the
|
|
|
|
# `#ci_cd_settings` relation needs to be created first
|
|
|
|
group_runners_enabled nil
|
2018-11-27 09:41:27 +00:00
|
|
|
import_status nil
|
|
|
|
import_jid nil
|
2017-08-09 09:31:25 +00: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
|
|
|
|
|
2018-10-05 13:41:11 +00:00
|
|
|
hash = {
|
2017-08-09 09:31:25 +00:00
|
|
|
wiki_access_level: evaluator.wiki_access_level,
|
|
|
|
builds_access_level: builds_access_level,
|
|
|
|
snippets_access_level: evaluator.snippets_access_level,
|
|
|
|
issues_access_level: evaluator.issues_access_level,
|
|
|
|
merge_requests_access_level: merge_requests_access_level,
|
2018-10-05 13:41:11 +00:00
|
|
|
repository_access_level: evaluator.repository_access_level
|
|
|
|
}
|
|
|
|
|
|
|
|
if ActiveRecord::Migrator.current_version >= PAGES_ACCESS_LEVEL_SCHEMA_VERSION
|
|
|
|
hash.store("pages_access_level", evaluator.pages_access_level)
|
|
|
|
end
|
|
|
|
|
|
|
|
project.project_feature.update(hash)
|
2017-08-09 09:31:25 +00:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
unless project.group || project.pending_delete
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(project.owner)
|
2017-08-09 09:31:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
project.group&.refresh_members_authorized_projects
|
2018-05-03 13:38:55 +00:00
|
|
|
|
|
|
|
# assign the delegated `#ci_cd_settings` attributes after create
|
|
|
|
project.reload.group_runners_enabled = evaluator.group_runners_enabled unless evaluator.group_runners_enabled.nil?
|
2018-11-27 09:41:27 +00:00
|
|
|
|
|
|
|
if evaluator.import_status
|
|
|
|
import_state = project.import_state || project.build_import_state
|
|
|
|
import_state.status = evaluator.import_status
|
|
|
|
import_state.jid = evaluator.import_jid
|
|
|
|
import_state.save
|
|
|
|
end
|
2017-08-09 09:31:25 +00:00
|
|
|
end
|
|
|
|
|
2014-07-31 17:13:27 +00:00
|
|
|
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-05-04 21:05:16 +00:00
|
|
|
|
2017-06-01 14:27:35 +00:00
|
|
|
trait :import_scheduled do
|
2018-05-07 17:25:51 +00:00
|
|
|
import_status :scheduled
|
2017-06-01 14:27:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :import_started do
|
2018-05-07 17:25:51 +00:00
|
|
|
import_status :started
|
2017-06-01 14:27:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :import_finished do
|
2018-05-07 17:25:51 +00:00
|
|
|
import_status :finished
|
2017-06-01 14:27:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :import_failed do
|
2018-05-07 17:25:51 +00:00
|
|
|
import_status :failed
|
2017-06-01 14:27:35 +00:00
|
|
|
end
|
|
|
|
|
2017-01-04 08:30:11 +00:00
|
|
|
trait :archived do
|
|
|
|
archived true
|
|
|
|
end
|
|
|
|
|
2017-12-01 13:58:49 +00:00
|
|
|
storage_version Project::LATEST_STORAGE_VERSION
|
|
|
|
|
|
|
|
trait :legacy_storage do
|
|
|
|
storage_version nil
|
2017-08-04 05:30:42 +00:00
|
|
|
end
|
|
|
|
|
2016-11-11 12:51:50 +00:00
|
|
|
trait :access_requestable do
|
|
|
|
request_access_enabled true
|
|
|
|
end
|
|
|
|
|
2017-05-01 20:15:16 +00:00
|
|
|
trait :with_avatar do
|
2018-02-01 19:24:59 +00:00
|
|
|
avatar { fixture_file_upload('spec/fixtures/dk.png') }
|
2017-05-01 20:15:16 +00:00
|
|
|
end
|
|
|
|
|
2018-01-23 19:03:02 +00:00
|
|
|
trait :with_export do
|
2018-06-25 13:10:26 +00:00
|
|
|
after(:create) do |project, _evaluator|
|
|
|
|
ProjectExportWorker.new.perform(project.creator.id, project.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-17 16:17:15 +00:00
|
|
|
trait :broken_storage do
|
|
|
|
after(:create) do |project|
|
|
|
|
project.update_column(:repository_storage, 'broken')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-03 14:21:15 +00:00
|
|
|
# Build a custom repository by specifying a hash of `filename => content` in
|
|
|
|
# the transient `files` attribute. Each file will be created in its own
|
|
|
|
# commit, operating against the master branch. So, the following call:
|
|
|
|
#
|
|
|
|
# create(:project, :custom_repo, files: { 'foo/a.txt' => 'foo', 'b.txt' => bar' })
|
|
|
|
#
|
|
|
|
# will create a repository containing two files, and two commits, in master
|
|
|
|
trait :custom_repo do
|
|
|
|
transient do
|
|
|
|
files {}
|
|
|
|
end
|
|
|
|
|
|
|
|
after :create do |project, evaluator|
|
|
|
|
raise "Failed to create repository!" unless project.create_repository
|
|
|
|
|
|
|
|
evaluator.files.each do |filename, content|
|
|
|
|
project.repository.create_file(
|
|
|
|
project.creator,
|
|
|
|
filename,
|
|
|
|
content,
|
|
|
|
message: "Automatically created file #{filename}",
|
|
|
|
branch_name: 'master'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-02 19:55:11 +00:00
|
|
|
# Test repository - https://gitlab.com/gitlab-org/gitlab-test
|
2017-01-17 04:06:18 +00:00
|
|
|
trait :repository do
|
2017-08-02 19:43:24 +00:00
|
|
|
test_repo
|
|
|
|
|
|
|
|
transient do
|
2017-08-09 09:31:25 +00:00
|
|
|
create_templates nil
|
2017-08-02 19:43:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
after :create do |project, evaluator|
|
2017-08-09 09:31:25 +00:00
|
|
|
if evaluator.create_templates
|
|
|
|
templates_path = "#{evaluator.create_templates}_templates"
|
2017-08-02 19:43:24 +00:00
|
|
|
|
|
|
|
project.repository.create_file(
|
2017-08-09 09:31:25 +00:00
|
|
|
project.creator,
|
|
|
|
".gitlab/#{templates_path}/bug.md",
|
2017-08-02 19:43:24 +00:00
|
|
|
'something valid',
|
|
|
|
message: 'test 3',
|
|
|
|
branch_name: 'master')
|
|
|
|
project.repository.create_file(
|
2017-08-09 09:31:25 +00:00
|
|
|
project.creator,
|
|
|
|
".gitlab/#{templates_path}/template_test.md",
|
2017-08-02 19:43:24 +00:00
|
|
|
'template_test',
|
|
|
|
message: 'test 1',
|
|
|
|
branch_name: 'master')
|
|
|
|
project.repository.create_file(
|
2017-08-09 09:31:25 +00:00
|
|
|
project.creator,
|
|
|
|
".gitlab/#{templates_path}/feature_proposal.md",
|
2017-08-02 19:43:24 +00:00
|
|
|
'feature_proposal',
|
|
|
|
message: 'test 2',
|
|
|
|
branch_name: 'master')
|
|
|
|
end
|
|
|
|
end
|
2017-01-17 04:06:18 +00:00
|
|
|
end
|
|
|
|
|
2016-05-04 21:05:16 +00:00
|
|
|
trait :empty_repo do
|
|
|
|
after(:create) do |project|
|
2017-03-08 17:04:44 +00:00
|
|
|
raise "Failed to create repository!" unless project.create_repository
|
2016-05-04 21:05:16 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-01 22:31:21 +00:00
|
|
|
|
2018-05-03 12:55:14 +00:00
|
|
|
trait :remote_mirror do
|
|
|
|
transient do
|
|
|
|
remote_name "remote_mirror_#{SecureRandom.hex}"
|
|
|
|
url "http://foo.com"
|
|
|
|
enabled true
|
|
|
|
end
|
|
|
|
after(:create) do |project, evaluator|
|
|
|
|
project.remote_mirrors.create!(url: evaluator.url, enabled: evaluator.enabled)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-18 13:52:55 +00:00
|
|
|
trait :stubbed_repository do
|
|
|
|
after(:build) do |project|
|
|
|
|
allow(project).to receive(:empty_repo?).and_return(false)
|
|
|
|
allow(project.repository).to receive(:empty?).and_return(false)
|
2016-05-04 21:05:16 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-01 22:31:21 +00:00
|
|
|
|
2017-09-06 05:16:26 +00:00
|
|
|
trait :wiki_repo do
|
|
|
|
after(:create) do |project|
|
|
|
|
raise 'Failed to create wiki repository!' unless project.create_wiki
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-19 07:44:58 +00:00
|
|
|
trait :read_only do
|
2017-09-06 02:24:31 +00:00
|
|
|
repository_read_only true
|
|
|
|
end
|
|
|
|
|
2016-09-23 07:42:07 +00:00
|
|
|
trait :broken_repo do
|
|
|
|
after(:create) do |project|
|
2017-03-08 17:04:44 +00:00
|
|
|
raise "Failed to create repository!" unless project.create_repository
|
2016-09-23 07:42:07 +00:00
|
|
|
|
2018-04-13 10:57:19 +00:00
|
|
|
project.gitlab_shell.rm_directory(project.repository_storage,
|
|
|
|
File.join("#{project.disk_path}.git", 'refs'))
|
2016-09-23 07:42:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-15 00:59:04 +00:00
|
|
|
trait :test_repo do
|
|
|
|
after :create do |project|
|
2017-05-10 15:31:50 +00:00
|
|
|
TestEnv.copy_repo(project,
|
|
|
|
bare_repo: TestEnv.factory_repo_path_bare,
|
|
|
|
refs: TestEnv::BRANCH_SHA)
|
2016-12-15 00:59:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-02 10:10:25 +00:00
|
|
|
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 }
|
2018-10-05 13:41:11 +00:00
|
|
|
trait(:pages_public) { pages_access_level ProjectFeature::PUBLIC }
|
|
|
|
trait(:pages_enabled) { pages_access_level ProjectFeature::ENABLED }
|
|
|
|
trait(:pages_disabled) { pages_access_level ProjectFeature::DISABLED }
|
|
|
|
trait(:pages_private) { pages_access_level ProjectFeature::PRIVATE }
|
2018-09-06 19:20:42 +00:00
|
|
|
|
|
|
|
trait :auto_devops do
|
|
|
|
association :auto_devops, factory: :project_auto_devops
|
|
|
|
end
|
2019-03-12 10:15:33 +00:00
|
|
|
|
|
|
|
trait :auto_devops_disabled do
|
|
|
|
association :auto_devops, factory: [:project_auto_devops, :disabled]
|
|
|
|
end
|
2014-07-31 17:13:27 +00:00
|
|
|
end
|
|
|
|
|
2014-11-30 08:50:15 +00:00
|
|
|
# Project with empty repository
|
|
|
|
#
|
|
|
|
# This is a case when you just created a project
|
|
|
|
# but not pushed any code there yet
|
2017-08-02 19:43:24 +00:00
|
|
|
factory :project_empty_repo, parent: :project do
|
2016-05-04 21:05:16 +00:00
|
|
|
empty_repo
|
2014-11-30 08:50:15 +00:00
|
|
|
end
|
|
|
|
|
2016-09-23 07:42:07 +00:00
|
|
|
# Project with broken repository
|
|
|
|
#
|
|
|
|
# Project with an invalid repository state
|
2017-08-02 19:43:24 +00:00
|
|
|
factory :project_broken_repo, parent: :project do
|
2016-09-23 07:42:07 +00:00
|
|
|
broken_repo
|
|
|
|
end
|
|
|
|
|
2017-08-02 19:43:24 +00:00
|
|
|
factory :forked_project_with_submodules, parent: :project do
|
2015-04-13 05:27:45 +00:00
|
|
|
path { 'forked-gitlabhq' }
|
|
|
|
|
|
|
|
after :create do |project|
|
2017-05-10 15:31:50 +00:00
|
|
|
TestEnv.copy_repo(project,
|
|
|
|
bare_repo: TestEnv.forked_repo_path_bare,
|
|
|
|
refs: TestEnv::FORKED_BRANCH_SHA)
|
2015-04-13 05:27:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-31 17:13:27 +00:00
|
|
|
factory :redmine_project, parent: :project do
|
2016-10-06 21:17:11 +00:00
|
|
|
has_external_issue_tracker true
|
|
|
|
|
2015-01-26 23:59:40 +00:00
|
|
|
after :create do |project|
|
|
|
|
project.create_redmine_service(
|
|
|
|
active: true,
|
|
|
|
properties: {
|
2015-01-27 06:08:27 +00:00
|
|
|
'project_url' => 'http://redmine/projects/project_name_in_redmine',
|
2017-06-30 12:47:53 +00:00
|
|
|
'issues_url' => 'http://redmine/projects/project_name_in_redmine/issues/:id',
|
2015-01-27 06:08:27 +00:00
|
|
|
'new_issue_url' => 'http://redmine/projects/project_name_in_redmine/issues/new'
|
2015-01-26 23:59:40 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
2014-07-31 17:13:27 +00:00
|
|
|
end
|
2015-04-29 18:28:24 +00:00
|
|
|
|
2019-02-18 17:08:36 +00:00
|
|
|
factory :youtrack_project, parent: :project do
|
|
|
|
has_external_issue_tracker true
|
|
|
|
|
|
|
|
after :create do |project|
|
|
|
|
project.create_youtrack_service(
|
|
|
|
active: true,
|
|
|
|
properties: {
|
|
|
|
'project_url' => 'http://youtrack/projects/project_guid_in_youtrack',
|
2019-02-21 10:39:44 +00:00
|
|
|
'issues_url' => 'http://youtrack/issues/:id'
|
2019-02-18 17:08:36 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-29 18:28:24 +00:00
|
|
|
factory :jira_project, parent: :project do
|
2016-10-06 21:17:11 +00:00
|
|
|
has_external_issue_tracker true
|
2017-03-06 14:18:59 +00:00
|
|
|
jira_service
|
2015-04-29 18:28:24 +00:00
|
|
|
end
|
2016-12-08 16:36:26 +00:00
|
|
|
|
2017-08-02 19:43:24 +00:00
|
|
|
factory :kubernetes_project, parent: :project do
|
2017-03-06 14:18:59 +00:00
|
|
|
kubernetes_service
|
2016-12-08 16:36:26 +00:00
|
|
|
end
|
2017-03-07 16:57:42 +00:00
|
|
|
|
2019-02-07 03:00:32 +00:00
|
|
|
factory :mock_deployment_project, parent: :project do
|
|
|
|
mock_deployment_service
|
|
|
|
end
|
|
|
|
|
2017-08-02 19:43:24 +00:00
|
|
|
factory :prometheus_project, parent: :project do
|
2017-03-07 16:57:42 +00:00
|
|
|
after :create do |project|
|
|
|
|
project.create_prometheus_service(
|
|
|
|
active: true,
|
|
|
|
properties: {
|
2018-02-07 00:53:18 +00:00
|
|
|
api_url: 'https://prometheus.example.com/',
|
2018-01-30 10:32:47 +00:00
|
|
|
manual_configuration: true
|
2017-03-07 16:57:42 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2014-07-31 17:13:27 +00:00
|
|
|
end
|