2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
require_relative '../support/helpers/test_env'
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
FactoryBot.define do
|
2019-03-02 22:35:43 +05:30
|
|
|
PAGES_ACCESS_LEVEL_SCHEMA_VERSION ||= 20180423204600
|
2018-12-05 23:21:45 +05:30
|
|
|
|
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/, '_') }
|
2016-11-03 12:29:30 +05:30
|
|
|
# Behaves differently to nil due to cache_has_external_issue_tracker
|
2019-12-21 20:55:43 +05:30
|
|
|
has_external_issue_tracker { false }
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
# Associations
|
|
|
|
namespace
|
|
|
|
creator { group ? create(:user) : namespace&.owner }
|
|
|
|
|
|
|
|
transient do
|
2018-10-15 14:42:47 +05:30
|
|
|
# Nest Project Feature attributes
|
2019-12-21 20:55:43 +05:30
|
|
|
wiki_access_level { ProjectFeature::ENABLED }
|
|
|
|
builds_access_level { ProjectFeature::ENABLED }
|
|
|
|
snippets_access_level { ProjectFeature::ENABLED }
|
|
|
|
issues_access_level { ProjectFeature::ENABLED }
|
2020-03-13 15:44:24 +05:30
|
|
|
forking_access_level { ProjectFeature::ENABLED }
|
2019-12-21 20:55:43 +05:30
|
|
|
merge_requests_access_level { ProjectFeature::ENABLED }
|
|
|
|
repository_access_level { ProjectFeature::ENABLED }
|
2019-09-30 21:07:59 +05:30
|
|
|
pages_access_level do
|
|
|
|
visibility_level == Gitlab::VisibilityLevel::PUBLIC ? ProjectFeature::ENABLED : ProjectFeature::PRIVATE
|
|
|
|
end
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
# we can't assign the delegated `#ci_cd_settings` attributes directly, as the
|
|
|
|
# `#ci_cd_settings` relation needs to be created first
|
2019-12-21 20:55:43 +05:30
|
|
|
group_runners_enabled { nil }
|
|
|
|
import_status { nil }
|
|
|
|
import_jid { nil }
|
2020-04-22 19:07:51 +05:30
|
|
|
import_correlation_id { nil }
|
|
|
|
import_last_error { nil }
|
2020-03-13 15:44:24 +05:30
|
|
|
forward_deployment_enabled { nil }
|
2018-03-17 18:26:18 +05:30
|
|
|
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-12-05 23:21:45 +05:30
|
|
|
hash = {
|
2018-03-17 18:26:18 +05:30
|
|
|
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,
|
2020-03-13 15:44:24 +05:30
|
|
|
forking_access_level: evaluator.forking_access_level,
|
2018-03-17 18:26:18 +05:30
|
|
|
merge_requests_access_level: merge_requests_access_level,
|
2018-12-05 23:21:45 +05:30
|
|
|
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)
|
2018-03-17 18:26:18 +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.
|
|
|
|
unless project.group || project.pending_delete
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(project.owner)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
project.group&.refresh_members_authorized_projects
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
# assign the delegated `#ci_cd_settings` attributes after create
|
|
|
|
project.reload.group_runners_enabled = evaluator.group_runners_enabled unless evaluator.group_runners_enabled.nil?
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
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
|
2020-04-22 19:07:51 +05:30
|
|
|
import_state.correlation_id_value = evaluator.import_correlation_id
|
|
|
|
import_state.last_error = evaluator.import_last_error
|
2019-02-15 15:39:39 +05:30
|
|
|
import_state.save
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
trait :public do
|
2019-12-21 20:55:43 +05:30
|
|
|
visibility_level { Gitlab::VisibilityLevel::PUBLIC }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
trait :internal do
|
2019-12-21 20:55:43 +05:30
|
|
|
visibility_level { Gitlab::VisibilityLevel::INTERNAL }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
trait :private do
|
2019-12-21 20:55:43 +05:30
|
|
|
visibility_level { Gitlab::VisibilityLevel::PRIVATE }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
trait :import_scheduled do
|
2019-12-21 20:55:43 +05:30
|
|
|
import_status { :scheduled }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
trait :import_started do
|
2019-12-21 20:55:43 +05:30
|
|
|
import_status { :started }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
trait :import_finished do
|
2019-12-21 20:55:43 +05:30
|
|
|
import_status { :finished }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
trait :import_failed do
|
2019-12-21 20:55:43 +05:30
|
|
|
import_status { :failed }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
trait :archived do
|
2019-12-21 20:55:43 +05:30
|
|
|
archived { true }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
trait :last_repository_check_failed do
|
|
|
|
last_repository_check_failed { true }
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
storage_version { Project::LATEST_STORAGE_VERSION }
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
trait :legacy_storage do
|
2019-12-21 20:55:43 +05:30
|
|
|
storage_version { nil }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
trait :request_access_disabled do
|
|
|
|
request_access_enabled { false }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_avatar do
|
2018-03-17 18:26:18 +05:30
|
|
|
avatar { fixture_file_upload('spec/fixtures/dk.png') }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_export do
|
2018-11-08 19:23:39 +05:30
|
|
|
after(:create) do |project, _evaluator|
|
|
|
|
ProjectExportWorker.new.perform(project.creator.id, project.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
trait :broken_storage do
|
|
|
|
after(:create) do |project|
|
|
|
|
project.update_column(:repository_storage, 'broken')
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
# 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
|
2019-12-21 20:55:43 +05:30
|
|
|
files { {} }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
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
|
2017-09-10 17:25:29 +05:30
|
|
|
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
|
2019-12-21 20:55:43 +05:30
|
|
|
create_templates { nil }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
after :create do |project, evaluator|
|
2018-03-17 18:26:18 +05:30
|
|
|
if evaluator.create_templates
|
|
|
|
templates_path = "#{evaluator.create_templates}_templates"
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
project.repository.create_file(
|
2018-03-17 18:26:18 +05:30
|
|
|
project.creator,
|
|
|
|
".gitlab/#{templates_path}/bug.md",
|
2017-09-10 17:25:29 +05:30
|
|
|
'something valid',
|
|
|
|
message: 'test 3',
|
|
|
|
branch_name: 'master')
|
|
|
|
project.repository.create_file(
|
2018-03-17 18:26:18 +05:30
|
|
|
project.creator,
|
|
|
|
".gitlab/#{templates_path}/template_test.md",
|
2017-09-10 17:25:29 +05:30
|
|
|
'template_test',
|
|
|
|
message: 'test 1',
|
|
|
|
branch_name: 'master')
|
|
|
|
project.repository.create_file(
|
2018-03-17 18:26:18 +05:30
|
|
|
project.creator,
|
|
|
|
".gitlab/#{templates_path}/feature_proposal.md",
|
2017-09-10 17:25:29 +05:30
|
|
|
'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
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :remote_mirror do
|
|
|
|
transient do
|
2019-12-21 20:55:43 +05:30
|
|
|
remote_name { "remote_mirror_#{SecureRandom.hex}" }
|
|
|
|
url { "http://foo.com" }
|
|
|
|
enabled { true }
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
after(:create) do |project, evaluator|
|
|
|
|
project.remote_mirrors.create!(url: evaluator.url, enabled: evaluator.enabled)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
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)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
trait :wiki_repo do
|
|
|
|
after(:create) do |project|
|
|
|
|
raise 'Failed to create wiki repository!' unless project.create_wiki
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :read_only do
|
2019-12-21 20:55:43 +05:30
|
|
|
repository_read_only { true }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
trait :broken_repo do
|
|
|
|
after(:create) do |project|
|
2019-12-26 22:10:19 +05:30
|
|
|
TestEnv.rm_storage_dir(project.repository_storage, "#{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
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
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 } }
|
2020-03-13 15:44:24 +05:30
|
|
|
trait(:forking_disabled) { forking_access_level { ProjectFeature::DISABLED } }
|
|
|
|
trait(:forking_enabled) { forking_access_level { ProjectFeature::ENABLED } }
|
|
|
|
trait(:forking_private) { forking_access_level { ProjectFeature::PRIVATE } }
|
2019-12-21 20:55:43 +05:30
|
|
|
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(:merge_requests_public) { merge_requests_access_level { ProjectFeature::PUBLIC } }
|
|
|
|
trait(:repository_enabled) { repository_access_level { ProjectFeature::ENABLED } }
|
|
|
|
trait(:repository_disabled) { repository_access_level { ProjectFeature::DISABLED } }
|
|
|
|
trait(:repository_private) { repository_access_level { ProjectFeature::PRIVATE } }
|
|
|
|
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-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
trait :auto_devops do
|
|
|
|
association :auto_devops, factory: :project_auto_devops
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
trait :auto_devops_disabled do
|
|
|
|
association :auto_devops, factory: [:project_auto_devops, :disabled]
|
|
|
|
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
|
2019-12-21 20:55:43 +05:30
|
|
|
has_external_issue_tracker { true }
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
redmine_service
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
factory :youtrack_project, parent: :project do
|
2019-12-21 20:55:43 +05:30
|
|
|
has_external_issue_tracker { true }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
youtrack_service
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
factory :jira_project, parent: :project do
|
2019-12-21 20:55:43 +05:30
|
|
|
has_external_issue_tracker { true }
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
jira_service
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
factory :mock_deployment_project, parent: :project do
|
|
|
|
mock_deployment_service
|
|
|
|
end
|
|
|
|
|
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: {
|
2018-03-17 18:26:18 +05:30
|
|
|
api_url: 'https://prometheus.example.com/',
|
|
|
|
manual_configuration: true
|
2015-09-11 14:41:01 +05:30
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|