summaryrefslogtreecommitdiff
path: root/spec/factories
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
commit9f46488805e86b1bc341ea1620b866016c2ce5ed (patch)
treef9748c7e287041e37d6da49e0a29c9511dc34768 /spec/factories
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
downloadgitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/factories')
-rw-r--r--spec/factories/alert_management/alerts.rb81
-rw-r--r--spec/factories/appearances.rb1
-rw-r--r--spec/factories/ci/builds.rb18
-rw-r--r--spec/factories/ci/daily_build_group_report_results.rb (renamed from spec/factories/ci/daily_report_results.rb)9
-rw-r--r--spec/factories/ci/freeze_periods.rb10
-rw-r--r--spec/factories/ci/instance_variables.rb13
-rw-r--r--spec/factories/ci/job_artifacts.rb74
-rw-r--r--spec/factories/ci/pipelines.rb24
-rw-r--r--spec/factories/ci/test_case.rb2
-rw-r--r--spec/factories/clusters/applications/helm.rb24
-rw-r--r--spec/factories/deploy_tokens.rb8
-rw-r--r--spec/factories/design_management/actions.rb13
-rw-r--r--spec/factories/design_management/design_at_version.rb23
-rw-r--r--spec/factories/design_management/designs.rb128
-rw-r--r--spec/factories/design_management/versions.rb142
-rw-r--r--spec/factories/events.rb14
-rw-r--r--spec/factories/git_wiki_commit_details.rb15
-rw-r--r--spec/factories/groups.rb10
-rw-r--r--spec/factories/identities.rb2
-rw-r--r--spec/factories/iterations.rb60
-rw-r--r--spec/factories/merge_requests.rb24
-rw-r--r--spec/factories/metrics/users_starred_dasboards.rb9
-rw-r--r--spec/factories/notes.rb19
-rw-r--r--spec/factories/plan_limits.rb11
-rw-r--r--spec/factories/plans.rb13
-rw-r--r--spec/factories/project_repository_storage_moves.rb14
-rw-r--r--spec/factories/project_wikis.rb11
-rw-r--r--spec/factories/projects.rb6
-rw-r--r--spec/factories/remote_mirrors.rb5
-rw-r--r--spec/factories/resource_state_event.rb10
-rw-r--r--spec/factories/sequences.rb1
-rw-r--r--spec/factories/services.rb7
-rw-r--r--spec/factories/uploads.rb6
-rw-r--r--spec/factories/usage_data.rb26
-rw-r--r--spec/factories/users.rb6
-rw-r--r--spec/factories/wiki_pages.rb44
-rw-r--r--spec/factories/wikis.rb21
37 files changed, 847 insertions, 57 deletions
diff --git a/spec/factories/alert_management/alerts.rb b/spec/factories/alert_management/alerts.rb
new file mode 100644
index 00000000000..01f40a7a465
--- /dev/null
+++ b/spec/factories/alert_management/alerts.rb
@@ -0,0 +1,81 @@
+# frozen_string_literal: true
+require 'ffaker'
+
+FactoryBot.define do
+ factory :alert_management_alert, class: 'AlertManagement::Alert' do
+ triggered
+ project
+ title { FFaker::Lorem.sentence }
+ started_at { Time.current }
+
+ trait :with_issue do
+ issue
+ end
+
+ trait :with_fingerprint do
+ fingerprint { SecureRandom.hex }
+ end
+
+ trait :with_service do
+ service { FFaker::Product.product_name }
+ end
+
+ trait :with_monitoring_tool do
+ monitoring_tool { FFaker::AWS.product_description }
+ end
+
+ trait :with_description do
+ description { FFaker::Lorem.sentence }
+ end
+
+ trait :with_host do
+ hosts { [FFaker::Internet.ip_v4_address] }
+ end
+
+ trait :with_ended_at do
+ ended_at { Time.current }
+ end
+
+ trait :without_ended_at do
+ ended_at { nil }
+ end
+
+ trait :triggered do
+ status { AlertManagement::Alert::STATUSES[:triggered] }
+ without_ended_at
+ end
+
+ trait :acknowledged do
+ status { AlertManagement::Alert::STATUSES[:acknowledged] }
+ without_ended_at
+ end
+
+ trait :resolved do
+ status { AlertManagement::Alert::STATUSES[:resolved] }
+ with_ended_at
+ end
+
+ trait :ignored do
+ status { AlertManagement::Alert::STATUSES[:ignored] }
+ without_ended_at
+ end
+
+ trait :low_severity do
+ severity { 'low' }
+ end
+
+ trait :prometheus do
+ monitoring_tool { Gitlab::AlertManagement::AlertParams::MONITORING_TOOLS[:prometheus] }
+ end
+
+ trait :all_fields do
+ with_issue
+ with_fingerprint
+ with_service
+ with_monitoring_tool
+ with_host
+ with_description
+ low_severity
+ end
+ end
+end
diff --git a/spec/factories/appearances.rb b/spec/factories/appearances.rb
index e2922662ea4..8101cd8d8bf 100644
--- a/spec/factories/appearances.rb
+++ b/spec/factories/appearances.rb
@@ -7,6 +7,7 @@ FactoryBot.define do
title { "GitLab Community Edition" }
description { "Open source software to collaborate on code" }
new_project_guidelines { "Custom project guidelines" }
+ profile_image_guidelines { "Custom profile image guidelines" }
end
trait :with_logo do
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb
index fb3c163dff1..26786aab12c 100644
--- a/spec/factories/ci/builds.rb
+++ b/spec/factories/ci/builds.rb
@@ -314,12 +314,30 @@ FactoryBot.define do
end
end
+ trait :broken_test_reports do
+ after(:build) do |build|
+ build.job_artifacts << create(:ci_job_artifact, :junit_with_corrupted_data, job: build)
+ end
+ end
+
+ trait :accessibility_reports do
+ after(:build) do |build|
+ build.job_artifacts << create(:ci_job_artifact, :accessibility, job: build)
+ end
+ end
+
trait :coverage_reports do
after(:build) do |build|
build.job_artifacts << create(:ci_job_artifact, :cobertura, job: build)
end
end
+ trait :terraform_reports do
+ after(:build) do |build|
+ build.job_artifacts << create(:ci_job_artifact, :terraform, job: build)
+ end
+ end
+
trait :expired do
artifacts_expire_at { 1.minute.ago }
end
diff --git a/spec/factories/ci/daily_report_results.rb b/spec/factories/ci/daily_build_group_report_results.rb
index e2255e8a134..8653316b51a 100644
--- a/spec/factories/ci/daily_report_results.rb
+++ b/spec/factories/ci/daily_build_group_report_results.rb
@@ -1,13 +1,14 @@
# frozen_string_literal: true
FactoryBot.define do
- factory :ci_daily_report_result, class: 'Ci::DailyReportResult' do
+ factory :ci_daily_build_group_report_result, class: 'Ci::DailyBuildGroupReportResult' do
ref_path { Gitlab::Git::BRANCH_REF_PREFIX + 'master' }
date { Time.zone.now.to_date }
project
last_pipeline factory: :ci_pipeline
- param_type { Ci::DailyReportResult.param_types[:coverage] }
- title { 'rspec' }
- value { 77.0 }
+ group_name { 'rspec' }
+ data do
+ { 'coverage' => 77.0 }
+ end
end
end
diff --git a/spec/factories/ci/freeze_periods.rb b/spec/factories/ci/freeze_periods.rb
new file mode 100644
index 00000000000..de48c2076c8
--- /dev/null
+++ b/spec/factories/ci/freeze_periods.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :ci_freeze_period, class: 'Ci::FreezePeriod' do
+ project
+ freeze_start { '0 23 * * 5' }
+ freeze_end { '0 7 * * 1' }
+ cron_timezone { 'UTC' }
+ end
+end
diff --git a/spec/factories/ci/instance_variables.rb b/spec/factories/ci/instance_variables.rb
new file mode 100644
index 00000000000..5a3551d3561
--- /dev/null
+++ b/spec/factories/ci/instance_variables.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :ci_instance_variable, class: 'Ci::InstanceVariable' do
+ sequence(:key) { |n| "VARIABLE_#{n}" }
+ value { 'VARIABLE_VALUE' }
+ masked { false }
+
+ trait(:protected) do
+ add_attribute(:protected) { true }
+ end
+ end
+end
diff --git a/spec/factories/ci/job_artifacts.rb b/spec/factories/ci/job_artifacts.rb
index 82383cfa2b0..26c09795a0b 100644
--- a/spec/factories/ci/job_artifacts.rb
+++ b/spec/factories/ci/job_artifacts.rb
@@ -139,6 +139,36 @@ FactoryBot.define do
end
end
+ trait :accessibility do
+ file_type { :accessibility }
+ file_format { :raw }
+
+ after(:build) do |artifact, _evaluator|
+ artifact.file = fixture_file_upload(
+ Rails.root.join('spec/fixtures/accessibility/pa11y_with_errors.json'), 'application/json')
+ end
+ end
+
+ trait :accessibility_with_invalid_url do
+ file_type { :accessibility }
+ file_format { :raw }
+
+ after(:build) do |artifact, _evaluator|
+ artifact.file = fixture_file_upload(
+ Rails.root.join('spec/fixtures/accessibility/pa11y_with_invalid_url.json'), 'application/json')
+ end
+ end
+
+ trait :accessibility_without_errors do
+ file_type { :accessibility }
+ file_format { :raw }
+
+ after(:build) do |artifact, _evaluator|
+ artifact.file = fixture_file_upload(
+ Rails.root.join('spec/fixtures/accessibility/pa11y_without_errors.json'), 'application/json')
+ end
+ end
+
trait :cobertura do
file_type { :cobertura }
file_format { :gzip }
@@ -149,6 +179,26 @@ FactoryBot.define do
end
end
+ trait :terraform do
+ file_type { :terraform }
+ file_format { :raw }
+
+ after(:build) do |artifact, evaluator|
+ artifact.file = fixture_file_upload(
+ Rails.root.join('spec/fixtures/terraform/tfplan.json'), 'application/json')
+ end
+ end
+
+ trait :terraform_with_corrupted_data do
+ file_type { :terraform }
+ file_format { :raw }
+
+ after(:build) do |artifact, evaluator|
+ artifact.file = fixture_file_upload(
+ Rails.root.join('spec/fixtures/terraform/tfplan_with_corrupted_data.json'), 'application/json')
+ end
+ end
+
trait :coverage_gocov_xml do
file_type { :cobertura }
file_format { :gzip }
@@ -181,11 +231,14 @@ FactoryBot.define do
trait :lsif do
file_type { :lsif }
- file_format { :gzip }
+ file_format { :zip }
+
+ transient do
+ file_path { Rails.root.join('spec/fixtures/lsif.json.gz') }
+ end
after(:build) do |artifact, evaluator|
- artifact.file = fixture_file_upload(
- Rails.root.join('spec/fixtures/lsif.json.gz'), 'application/x-gzip')
+ artifact.file = fixture_file_upload(evaluator.file_path, 'application/x-gzip')
end
end
@@ -199,6 +252,21 @@ FactoryBot.define do
end
end
+ trait :cluster_applications do
+ file_type { :cluster_applications }
+ file_format { :gzip }
+
+ transient do
+ file do
+ fixture_file_upload(Rails.root.join('spec/fixtures/helm/helm_list_v2_prometheus_missing.json.gz'), 'application/x-gzip')
+ end
+ end
+
+ after(:build) do |artifact, evaluator|
+ artifact.file = evaluator.file
+ end
+ end
+
trait :correct_checksum do
after(:build) do |artifact, evaluator|
artifact.file_sha256 = Digest::SHA256.file(artifact.file.path).hexdigest
diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb
index 257dd3337ba..0b3653a01ed 100644
--- a/spec/factories/ci/pipelines.rb
+++ b/spec/factories/ci/pipelines.rb
@@ -75,6 +75,22 @@ FactoryBot.define do
end
end
+ trait :with_broken_test_reports do
+ status { :success }
+
+ after(:build) do |pipeline, _evaluator|
+ pipeline.builds << build(:ci_build, :broken_test_reports, pipeline: pipeline, project: pipeline.project)
+ end
+ end
+
+ trait :with_accessibility_reports do
+ status { :success }
+
+ after(:build) do |pipeline, evaluator|
+ pipeline.builds << build(:ci_build, :accessibility_reports, pipeline: pipeline, project: pipeline.project)
+ end
+ end
+
trait :with_coverage_reports do
status { :success }
@@ -83,6 +99,14 @@ FactoryBot.define do
end
end
+ trait :with_terraform_reports do
+ status { :success }
+
+ after(:build) do |pipeline, evaluator|
+ pipeline.builds << build(:ci_build, :terraform_reports, pipeline: pipeline, project: pipeline.project)
+ end
+ end
+
trait :with_exposed_artifacts do
status { :success }
diff --git a/spec/factories/ci/test_case.rb b/spec/factories/ci/test_case.rb
index bb1508c0d75..0639aac566a 100644
--- a/spec/factories/ci/test_case.rb
+++ b/spec/factories/ci/test_case.rb
@@ -16,7 +16,7 @@ FactoryBot.define do
system_output { "Failure/Error: is_expected.to eq(300) expected: 300 got: -100" }
end
- trait :with_attachment do
+ trait :failed_with_attachment do
status { Gitlab::Ci::Reports::TestCase::STATUS_FAILED }
attachment { "some/path.png" }
end
diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb
index 728c83e01b4..c49c26f06e5 100644
--- a/spec/factories/clusters/applications/helm.rb
+++ b/spec/factories/clusters/applications/helm.rb
@@ -65,6 +65,10 @@ FactoryBot.define do
status_reason { 'something went wrong' }
end
+ trait :uninstalled do
+ status { 10 }
+ end
+
trait :timed_out do
installing
updated_at { ClusterWaitForAppInstallationWorker::TIMEOUT.ago }
@@ -77,6 +81,24 @@ FactoryBot.define do
trait :no_helm_installed do
cluster factory: %i(cluster provided_by_gcp)
end
+
+ trait :modsecurity_blocking do
+ modsecurity_enabled { true }
+ modsecurity_mode { :blocking }
+ end
+
+ trait :modsecurity_logging do
+ modsecurity_enabled { true }
+ modsecurity_mode { :logging }
+ end
+
+ trait :modsecurity_disabled do
+ modsecurity_enabled { false }
+ end
+
+ trait :modsecurity_not_installed do
+ modsecurity_enabled { nil }
+ end
end
factory :clusters_applications_cert_manager, class: 'Clusters::Applications::CertManager' do
@@ -142,6 +164,8 @@ FactoryBot.define do
factory :clusters_applications_fluentd, class: 'Clusters::Applications::Fluentd' do
host { 'example.com' }
+ waf_log_enabled { true }
+ cilium_log_enabled { true }
cluster factory: %i(cluster with_installed_helm provided_by_gcp)
trait :no_helm_installed do
diff --git a/spec/factories/deploy_tokens.rb b/spec/factories/deploy_tokens.rb
index 657915f9976..d4127f78ebf 100644
--- a/spec/factories/deploy_tokens.rb
+++ b/spec/factories/deploy_tokens.rb
@@ -8,6 +8,8 @@ FactoryBot.define do
read_repository { true }
read_registry { true }
write_registry { false }
+ read_package_registry { false }
+ write_package_registry { false }
revoked { false }
expires_at { 5.days.from_now }
deploy_token_type { DeployToken.deploy_token_types[:project_type] }
@@ -31,5 +33,11 @@ FactoryBot.define do
trait :project do
deploy_token_type { DeployToken.deploy_token_types[:project_type] }
end
+
+ trait :all_scopes do
+ write_registry { true}
+ read_package_registry { true }
+ write_package_registry { true }
+ end
end
end
diff --git a/spec/factories/design_management/actions.rb b/spec/factories/design_management/actions.rb
new file mode 100644
index 00000000000..e2561f98f52
--- /dev/null
+++ b/spec/factories/design_management/actions.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :design_action, class: 'DesignManagement::Action' do
+ design
+ association :version, factory: :design_version
+ event { :creation }
+
+ trait :with_image_v432x230 do
+ image_v432x230 { fixture_file_upload('spec/fixtures/dk.png') }
+ end
+ end
+end
diff --git a/spec/factories/design_management/design_at_version.rb b/spec/factories/design_management/design_at_version.rb
new file mode 100644
index 00000000000..b73df71595c
--- /dev/null
+++ b/spec/factories/design_management/design_at_version.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :design_at_version, class: 'DesignManagement::DesignAtVersion' do
+ skip_create # This is not an Active::Record model.
+
+ design { nil }
+
+ version { nil }
+
+ transient do
+ issue { design&.issue || version&.issue || create(:issue) }
+ end
+
+ initialize_with do
+ attrs = attributes.dup
+ attrs[:design] ||= create(:design, issue: issue)
+ attrs[:version] ||= create(:design_version, issue: issue)
+
+ new(attrs)
+ end
+ end
+end
diff --git a/spec/factories/design_management/designs.rb b/spec/factories/design_management/designs.rb
new file mode 100644
index 00000000000..59d4cc56f95
--- /dev/null
+++ b/spec/factories/design_management/designs.rb
@@ -0,0 +1,128 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :design, class: 'DesignManagement::Design' do
+ issue { create(:issue) }
+ project { issue&.project || create(:project) }
+ sequence(:filename) { |n| "homescreen-#{n}.jpg" }
+
+ transient do
+ author { issue.author }
+ end
+
+ trait :importing do
+ issue { nil }
+
+ importing { true }
+ imported { false }
+ end
+
+ trait :imported do
+ importing { false }
+ imported { true }
+ end
+
+ create_versions = ->(design, evaluator, commit_version) do
+ unless evaluator.versions_count.zero?
+ project = design.project
+ issue = design.issue
+ repository = project.design_repository
+ repository.create_if_not_exists
+ dv_table_name = DesignManagement::Action.table_name
+ updates = [0, evaluator.versions_count - (evaluator.deleted ? 2 : 1)].max
+
+ run_action = ->(action) do
+ sha = commit_version[action]
+ version = DesignManagement::Version.new(sha: sha, issue: issue, author: evaluator.author)
+ version.save(validate: false) # We need it to have an ID, validate later
+ Gitlab::Database.bulk_insert(dv_table_name, [action.row_attrs(version)])
+ end
+
+ # always a creation
+ run_action[DesignManagement::DesignAction.new(design, :create, evaluator.file)]
+
+ # 0 or more updates
+ updates.times do
+ run_action[DesignManagement::DesignAction.new(design, :update, evaluator.file)]
+ end
+
+ # and maybe a deletion
+ run_action[DesignManagement::DesignAction.new(design, :delete)] if evaluator.deleted
+ end
+
+ design.clear_version_cache
+ end
+
+ # Use this trait to build designs that are backed by Git LFS, committed
+ # to the repository, and with an LfsObject correctly created for it.
+ trait :with_lfs_file do
+ with_file
+
+ transient do
+ raw_file { fixture_file_upload('spec/fixtures/dk.png', 'image/png') }
+ lfs_pointer { Gitlab::Git::LfsPointerFile.new(SecureRandom.random_bytes) }
+ file { lfs_pointer.pointer }
+ end
+
+ after :create do |design, evaluator|
+ lfs_object = create(:lfs_object, file: evaluator.raw_file, oid: evaluator.lfs_pointer.sha256, size: evaluator.lfs_pointer.size)
+ create(:lfs_objects_project, project: design.project, lfs_object: lfs_object, repository_type: :design)
+ end
+ end
+
+ # Use this trait if you want versions in a particular history, but don't
+ # want to pay for gitlay calls.
+ trait :with_versions do
+ transient do
+ deleted { false }
+ versions_count { 1 }
+ sequence(:file) { |n| "some-file-content-#{n}" }
+ end
+
+ after :create do |design, evaluator|
+ counter = (1..).lazy
+
+ # Just produce a SHA by hashing the action and a monotonic counter
+ commit_version = ->(action) do
+ Digest::SHA1.hexdigest("#{action.gitaly_action}.#{counter.next}")
+ end
+
+ create_versions[design, evaluator, commit_version]
+ end
+ end
+
+ # Use this trait to build designs that have commits in the repository
+ # and files that can be retrieved.
+ trait :with_file do
+ transient do
+ deleted { false }
+ versions_count { 1 }
+ file { File.join(Rails.root, 'spec/fixtures/dk.png') }
+ end
+
+ after :create do |design, evaluator|
+ project = design.project
+ repository = project.design_repository
+
+ commit_version = ->(action) do
+ repository.multi_action(
+ evaluator.author,
+ branch_name: 'master',
+ message: "#{action.action} for #{design.filename}",
+ actions: [action.gitaly_action]
+ )
+ end
+
+ create_versions[design, evaluator, commit_version]
+ end
+ end
+
+ trait :with_smaller_image_versions do
+ with_lfs_file
+
+ after :create do |design|
+ design.versions.each { |v| DesignManagement::GenerateImageVersionsService.new(v).execute }
+ end
+ end
+ end
+end
diff --git a/spec/factories/design_management/versions.rb b/spec/factories/design_management/versions.rb
new file mode 100644
index 00000000000..e6d17ba691c
--- /dev/null
+++ b/spec/factories/design_management/versions.rb
@@ -0,0 +1,142 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :design_version, class: 'DesignManagement::Version' do
+ sha
+ issue { designs.first&.issue || create(:issue) }
+ author { issue&.author || create(:user) }
+
+ transient do
+ designs_count { 1 }
+ created_designs { [] }
+ modified_designs { [] }
+ deleted_designs { [] }
+ end
+
+ # Warning: this will intentionally result in an invalid version!
+ trait :empty do
+ designs_count { 0 }
+ end
+
+ trait :importing do
+ issue { nil }
+
+ designs_count { 0 }
+ importing { true }
+ imported { false }
+ end
+
+ trait :imported do
+ importing { false }
+ imported { true }
+ end
+
+ after(:build) do |version, evaluator|
+ # By default all designs are created_designs, so just add them.
+ specific_designs = [].concat(
+ evaluator.created_designs,
+ evaluator.modified_designs,
+ evaluator.deleted_designs
+ )
+ version.designs += specific_designs
+
+ unless evaluator.designs_count.zero? || version.designs.present?
+ version.designs << create(:design, issue: version.issue)
+ end
+ end
+
+ after :create do |version, evaluator|
+ # FactoryBot does not like methods, so we use lambdas instead
+ events = DesignManagement::Action.events
+
+ version.actions
+ .where(design_id: evaluator.modified_designs.map(&:id))
+ .update_all(event: events[:modification])
+
+ version.actions
+ .where(design_id: evaluator.deleted_designs.map(&:id))
+ .update_all(event: events[:deletion])
+
+ version.designs.reload
+ # Ensure version.issue == design.issue for all version.designs
+ version.designs.update_all(issue_id: version.issue_id)
+
+ needed = evaluator.designs_count
+ have = version.designs.size
+
+ create_list(:design, [0, needed - have].max, issue: version.issue).each do |d|
+ version.designs << d
+ end
+
+ version.actions.reset
+ end
+
+ # Use this trait to build versions with designs that are backed by Git LFS, committed
+ # to the repository, and with an LfsObject correctly created for it.
+ trait :with_lfs_file do
+ committed
+
+ transient do
+ raw_file { fixture_file_upload('spec/fixtures/dk.png', 'image/png') }
+ lfs_pointer { Gitlab::Git::LfsPointerFile.new(SecureRandom.random_bytes) }
+ file { lfs_pointer.pointer }
+ end
+
+ after :create do |version, evaluator|
+ lfs_object = create(:lfs_object, file: evaluator.raw_file, oid: evaluator.lfs_pointer.sha256, size: evaluator.lfs_pointer.size)
+ create(:lfs_objects_project, project: version.project, lfs_object: lfs_object, repository_type: :design)
+ end
+ end
+
+ # This trait is for versions that must be present in the git repository.
+ trait :committed do
+ transient do
+ file { File.join(Rails.root, 'spec/fixtures/dk.png') }
+ end
+
+ after :create do |version, evaluator|
+ project = version.issue.project
+ repository = project.design_repository
+ repository.create_if_not_exists
+
+ designs = version.designs_by_event
+ base_change = { content: evaluator.file }
+
+ actions = %w[modification deletion].flat_map { |k| designs.fetch(k, []) }.map do |design|
+ base_change.merge(action: :create, file_path: design.full_path)
+ end
+
+ if actions.present?
+ repository.multi_action(
+ evaluator.author,
+ branch_name: 'master',
+ message: "created #{actions.size} files",
+ actions: actions
+ )
+ end
+
+ mapping = {
+ 'creation' => :create,
+ 'modification' => :update,
+ 'deletion' => :delete
+ }
+
+ version_actions = designs.flat_map do |(event, designs)|
+ base = event == 'deletion' ? {} : base_change
+ designs.map do |design|
+ base.merge(action: mapping[event], file_path: design.full_path)
+ end
+ end
+
+ sha = repository.multi_action(
+ evaluator.author,
+ branch_name: 'master',
+ message: "edited #{version_actions.size} files",
+ actions: version_actions
+ )
+
+ version.update(sha: sha)
+ end
+ end
+ end
+end
diff --git a/spec/factories/events.rb b/spec/factories/events.rb
index 5b456bb58ff..ed6cb3505f4 100644
--- a/spec/factories/events.rb
+++ b/spec/factories/events.rb
@@ -25,13 +25,23 @@ FactoryBot.define do
factory :wiki_page_event do
action { Event::CREATED }
- project { @overrides[:wiki_page]&.project || create(:project, :wiki_repo) }
+ project { @overrides[:wiki_page]&.container || create(:project, :wiki_repo) }
target { create(:wiki_page_meta, :for_wiki_page, wiki_page: wiki_page) }
transient do
- wiki_page { create(:wiki_page, project: project) }
+ wiki_page { create(:wiki_page, container: project) }
end
end
+
+ trait :for_design do
+ transient do
+ design { create(:design, issue: create(:issue, project: project)) }
+ note { create(:note, author: author, project: project, noteable: design) }
+ end
+
+ action { Event::COMMENTED }
+ target { note }
+ end
end
factory :push_event, class: 'PushEvent' do
diff --git a/spec/factories/git_wiki_commit_details.rb b/spec/factories/git_wiki_commit_details.rb
new file mode 100644
index 00000000000..b35f102fd4d
--- /dev/null
+++ b/spec/factories/git_wiki_commit_details.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :git_wiki_commit_details, class: 'Gitlab::Git::Wiki::CommitDetails' do
+ skip_create
+
+ transient do
+ author { create(:user) }
+ end
+
+ sequence(:message) { |n| "Commit message #{n}" }
+
+ initialize_with { new(author.id, author.username, author.name, author.email, message) }
+ end
+end
diff --git a/spec/factories/groups.rb b/spec/factories/groups.rb
index 4b6c1756d1e..d51c437f83a 100644
--- a/spec/factories/groups.rb
+++ b/spec/factories/groups.rb
@@ -6,7 +6,7 @@ FactoryBot.define do
path { name.downcase.gsub(/\s/, '_') }
type { 'Group' }
owner { nil }
- project_creation_level { ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS}
+ project_creation_level { ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS }
after(:create) do |group|
if group.owner
@@ -17,15 +17,15 @@ FactoryBot.define do
end
trait :public do
- visibility_level { Gitlab::VisibilityLevel::PUBLIC}
+ visibility_level { Gitlab::VisibilityLevel::PUBLIC }
end
trait :internal do
- visibility_level {Gitlab::VisibilityLevel::INTERNAL}
+ visibility_level {Gitlab::VisibilityLevel::INTERNAL }
end
trait :private do
- visibility_level { Gitlab::VisibilityLevel::PRIVATE}
+ visibility_level { Gitlab::VisibilityLevel::PRIVATE }
end
trait :with_avatar do
@@ -49,7 +49,7 @@ FactoryBot.define do
end
trait :owner_subgroup_creation_only do
- subgroup_creation_level { ::Gitlab::Access::OWNER_SUBGROUP_ACCESS}
+ subgroup_creation_level { ::Gitlab::Access::OWNER_SUBGROUP_ACCESS }
end
end
end
diff --git a/spec/factories/identities.rb b/spec/factories/identities.rb
index a2615ce30c3..fda4bfa589b 100644
--- a/spec/factories/identities.rb
+++ b/spec/factories/identities.rb
@@ -3,6 +3,6 @@
FactoryBot.define do
factory :identity do
provider { 'ldapmain' }
- extern_uid { 'my-ldap-id' }
+ sequence(:extern_uid) { |n| "my-ldap-id-#{n}" }
end
end
diff --git a/spec/factories/iterations.rb b/spec/factories/iterations.rb
new file mode 100644
index 00000000000..f6be1d9d752
--- /dev/null
+++ b/spec/factories/iterations.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ sequence(:sequential_date) do |n|
+ n.days.from_now
+ end
+
+ factory :iteration do
+ title
+ start_date { generate(:sequential_date) }
+ due_date { generate(:sequential_date) }
+
+ transient do
+ project { nil }
+ group { nil }
+ project_id { nil }
+ group_id { nil }
+ resource_parent { nil }
+ end
+
+ trait :upcoming do
+ state_enum { Iteration::STATE_ENUM_MAP[:upcoming] }
+ end
+
+ trait :started do
+ state_enum { Iteration::STATE_ENUM_MAP[:started] }
+ end
+
+ trait :closed do
+ state_enum { Iteration::STATE_ENUM_MAP[:closed] }
+ end
+
+ trait(:skip_future_date_validation) do
+ after(:stub, :build) do |iteration|
+ iteration.skip_future_date_validation = true
+ end
+ end
+
+ after(:build, :stub) do |iteration, evaluator|
+ if evaluator.group
+ iteration.group = evaluator.group
+ elsif evaluator.group_id
+ iteration.group_id = evaluator.group_id
+ elsif evaluator.project
+ iteration.project = evaluator.project
+ elsif evaluator.project_id
+ iteration.project_id = evaluator.project_id
+ elsif evaluator.resource_parent
+ id = evaluator.resource_parent.id
+ evaluator.resource_parent.is_a?(Group) ? evaluator.group_id = id : evaluator.project_id = id
+ else
+ iteration.project = create(:project)
+ end
+ end
+
+ factory :upcoming_iteration, traits: [:upcoming]
+ factory :started_iteration, traits: [:started]
+ factory :closed_iteration, traits: [:closed]
+ end
+end
diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb
index abccd775c8a..b10c04a37f7 100644
--- a/spec/factories/merge_requests.rb
+++ b/spec/factories/merge_requests.rb
@@ -121,6 +121,18 @@ FactoryBot.define do
end
end
+ trait :with_accessibility_reports do
+ after(:build) do |merge_request|
+ merge_request.head_pipeline = build(
+ :ci_pipeline,
+ :success,
+ :with_accessibility_reports,
+ project: merge_request.source_project,
+ ref: merge_request.source_branch,
+ sha: merge_request.diff_head_sha)
+ end
+ end
+
trait :with_coverage_reports do
after(:build) do |merge_request|
merge_request.head_pipeline = build(
@@ -133,6 +145,18 @@ FactoryBot.define do
end
end
+ trait :with_terraform_reports do
+ after(:build) do |merge_request|
+ merge_request.head_pipeline = build(
+ :ci_pipeline,
+ :success,
+ :with_terraform_reports,
+ project: merge_request.source_project,
+ ref: merge_request.source_branch,
+ sha: merge_request.diff_head_sha)
+ end
+ end
+
trait :with_exposed_artifacts do
after(:build) do |merge_request|
merge_request.head_pipeline = build(
diff --git a/spec/factories/metrics/users_starred_dasboards.rb b/spec/factories/metrics/users_starred_dasboards.rb
new file mode 100644
index 00000000000..06fe7735e9a
--- /dev/null
+++ b/spec/factories/metrics/users_starred_dasboards.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :metrics_users_starred_dashboard, class: '::Metrics::UsersStarredDashboard' do
+ dashboard_path { "custom_dashboard.yml" }
+ user
+ project
+ end
+end
diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb
index fdd1a9a18b2..7c3ba122b5a 100644
--- a/spec/factories/notes.rb
+++ b/spec/factories/notes.rb
@@ -16,6 +16,7 @@ FactoryBot.define do
factory :note_on_merge_request, traits: [:on_merge_request]
factory :note_on_project_snippet, traits: [:on_project_snippet]
factory :note_on_personal_snippet, traits: [:on_personal_snippet]
+ factory :note_on_design, traits: [:on_design]
factory :system_note, traits: [:system]
factory :discussion_note, class: 'DiscussionNote'
@@ -107,6 +108,10 @@ FactoryBot.define do
end
end
+ factory :diff_note_on_design, parent: :note, traits: [:on_design], class: 'DiffNote' do
+ position { build(:image_diff_position, file: noteable.full_path, diff_refs: noteable.diff_refs) }
+ end
+
trait :on_commit do
association :project, :repository
noteable { nil }
@@ -136,6 +141,20 @@ FactoryBot.define do
project { nil }
end
+ trait :on_design do
+ transient do
+ issue { association(:issue, project: project) }
+ end
+ noteable { association(:design, :with_file, issue: issue) }
+
+ after(:build) do |note|
+ next if note.project == note.noteable.project
+
+ # note validations require consistency between these two objects
+ note.project = note.noteable.project
+ end
+ end
+
trait :system do
system { true }
end
diff --git a/spec/factories/plan_limits.rb b/spec/factories/plan_limits.rb
new file mode 100644
index 00000000000..4aea09618d0
--- /dev/null
+++ b/spec/factories/plan_limits.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :plan_limits do
+ plan
+
+ trait :default_plan do
+ plan factory: :default_plan
+ end
+ end
+end
diff --git a/spec/factories/plans.rb b/spec/factories/plans.rb
new file mode 100644
index 00000000000..81506edcf16
--- /dev/null
+++ b/spec/factories/plans.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :plan do
+ Plan.all_plans.each do |plan|
+ factory :"#{plan}_plan" do
+ name { plan }
+ title { name.titleize }
+ initialize_with { Plan.find_or_create_by(name: plan) }
+ end
+ end
+ end
+end
diff --git a/spec/factories/project_repository_storage_moves.rb b/spec/factories/project_repository_storage_moves.rb
new file mode 100644
index 00000000000..aa8576834eb
--- /dev/null
+++ b/spec/factories/project_repository_storage_moves.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :project_repository_storage_move, class: 'ProjectRepositoryStorageMove' do
+ project
+
+ source_storage_name { 'default' }
+ destination_storage_name { 'default' }
+
+ trait :scheduled do
+ state { ProjectRepositoryStorageMove.state_machines[:state].states[:scheduled].value }
+ end
+ end
+end
diff --git a/spec/factories/project_wikis.rb b/spec/factories/project_wikis.rb
deleted file mode 100644
index 401402614f4..00000000000
--- a/spec/factories/project_wikis.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-
-FactoryBot.define do
- factory :project_wiki do
- skip_create
-
- association :project, :wiki_repo
- user { project.creator }
- initialize_with { new(project, user) }
- end
-end
diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb
index 64321c9f319..45caa7a2b6a 100644
--- a/spec/factories/projects.rb
+++ b/spec/factories/projects.rb
@@ -215,6 +215,12 @@ FactoryBot.define do
end
end
+ trait :design_repo do
+ after(:create) do |project|
+ raise 'Failed to create design repository!' unless project.design_repository.create_if_not_exists
+ end
+ end
+
trait :remote_mirror do
transient do
remote_name { "remote_mirror_#{SecureRandom.hex}" }
diff --git a/spec/factories/remote_mirrors.rb b/spec/factories/remote_mirrors.rb
index 124c0510cab..aa0ace30d90 100644
--- a/spec/factories/remote_mirrors.rb
+++ b/spec/factories/remote_mirrors.rb
@@ -4,5 +4,10 @@ FactoryBot.define do
factory :remote_mirror, class: 'RemoteMirror' do
association :project, :repository
url { "http://foo:bar@test.com" }
+
+ trait :ssh do
+ url { 'ssh://git@test.com:foo/bar.git' }
+ auth_method { 'ssh_public_key' }
+ end
end
end
diff --git a/spec/factories/resource_state_event.rb b/spec/factories/resource_state_event.rb
new file mode 100644
index 00000000000..e3de462b797
--- /dev/null
+++ b/spec/factories/resource_state_event.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :resource_state_event do
+ issue { merge_request.nil? ? create(:issue) : nil }
+ merge_request { nil }
+ state { :opened }
+ user { issue&.author || merge_request&.author || create(:user) }
+ end
+end
diff --git a/spec/factories/sequences.rb b/spec/factories/sequences.rb
index cdc64a8502e..ca0804965df 100644
--- a/spec/factories/sequences.rb
+++ b/spec/factories/sequences.rb
@@ -12,4 +12,5 @@ FactoryBot.define do
sequence(:branch) { |n| "my-branch-#{n}" }
sequence(:past_time) { |n| 4.hours.ago + (2 * n).seconds }
sequence(:iid)
+ sequence(:sha) { |n| Digest::SHA1.hexdigest("commit-like-#{n}") }
end
diff --git a/spec/factories/services.rb b/spec/factories/services.rb
index c011a9e3bb4..b6696769da9 100644
--- a/spec/factories/services.rb
+++ b/spec/factories/services.rb
@@ -158,6 +158,13 @@ FactoryBot.define do
token { 'test_token' }
end
+ factory :slack_service do
+ project
+ active { true }
+ webhook { 'https://slack.service.url' }
+ type { 'SlackService' }
+ end
+
# this is for testing storing values inside properties, which is deprecated and will be removed in
# https://gitlab.com/gitlab-org/gitlab/issues/29404
trait :without_properties_callback do
diff --git a/spec/factories/uploads.rb b/spec/factories/uploads.rb
index a060cd7d6f8..b19af277cc3 100644
--- a/spec/factories/uploads.rb
+++ b/spec/factories/uploads.rb
@@ -65,5 +65,11 @@ FactoryBot.define do
model { create(:note) }
uploader { "AttachmentUploader" }
end
+
+ trait :design_action_image_v432x230_upload do
+ mount_point { :image_v432x230 }
+ model { create(:design_action) }
+ uploader { ::DesignManagement::DesignV432x230Uploader.name }
+ end
end
end
diff --git a/spec/factories/usage_data.rb b/spec/factories/usage_data.rb
index b633038b83b..8fe0018b5a6 100644
--- a/spec/factories/usage_data.rb
+++ b/spec/factories/usage_data.rb
@@ -12,6 +12,11 @@ FactoryBot.define do
create(:jira_service, :jira_cloud_service, project: projects[2])
create(:jira_service, :without_properties_callback, project: projects[3],
properties: { url: 'https://mysite.atlassian.net' })
+ jira_label = create(:label, project: projects[0])
+ create(:jira_import_state, :finished, project: projects[0], label: jira_label, failed_to_import_count: 2, imported_issues_count: 7, total_issue_count: 9)
+ create(:jira_import_state, :finished, project: projects[1], label: jira_label, imported_issues_count: 3, total_issue_count: 3)
+ create(:jira_import_state, :finished, project: projects[1], label: jira_label, imported_issues_count: 3)
+ create(:jira_import_state, :scheduled, project: projects[1], label: jira_label)
create(:prometheus_service, project: projects[1])
create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true)
create(:service, project: projects[1], type: 'SlackService', active: true)
@@ -23,11 +28,10 @@ FactoryBot.define do
create(:project_error_tracking_setting, project: projects[1], enabled: false)
create(:alerts_service, project: projects[0])
create(:alerts_service, :inactive, project: projects[1])
- create_list(:issue, 2, project: projects[0], author: User.alert_bot)
+ alert_bot_issues = create_list(:issue, 2, project: projects[0], author: User.alert_bot)
create_list(:issue, 2, project: projects[1], author: User.alert_bot)
- create_list(:issue, 4, project: projects[0])
- create(:prometheus_alert, project: projects[0])
- create(:prometheus_alert, project: projects[0])
+ issues = create_list(:issue, 4, project: projects[0])
+ create_list(:prometheus_alert, 2, project: projects[0])
create(:prometheus_alert, project: projects[1])
create(:zoom_meeting, project: projects[0], issue: projects[0].issues[0], issue_status: :added)
create_list(:zoom_meeting, 2, project: projects[0], issue: projects[0].issues[1], issue_status: :removed)
@@ -35,6 +39,20 @@ FactoryBot.define do
create_list(:zoom_meeting, 2, project: projects[0], issue: projects[0].issues[2], issue_status: :removed)
create(:sentry_issue, issue: projects[0].issues[0])
+ # Incident Labeled Issues
+ incident_label_attrs = IncidentManagement::CreateIssueService::INCIDENT_LABEL
+ incident_label = create(:label, project: projects[0], **incident_label_attrs)
+ create(:labeled_issue, project: projects[0], labels: [incident_label])
+ incident_group = create(:group)
+ incident_label_scoped_to_project = create(:label, project: projects[1], **incident_label_attrs)
+ incident_label_scoped_to_group = create(:group_label, group: incident_group, **incident_label_attrs)
+ create(:labeled_issue, project: projects[1], labels: [incident_label_scoped_to_project])
+ create(:labeled_issue, project: projects[1], labels: [incident_label_scoped_to_group])
+
+ # Alert Issues
+ create(:alert_management_alert, issue: issues[0], project: projects[0])
+ create(:alert_management_alert, issue: alert_bot_issues[0], project: projects[0])
+
# Enabled clusters
gcp_cluster = create(:cluster_provider_gcp, :created).cluster
create(:cluster_provider_aws, :created)
diff --git a/spec/factories/users.rb b/spec/factories/users.rb
index f274503f0e7..2f5cc404143 100644
--- a/spec/factories/users.rb
+++ b/spec/factories/users.rb
@@ -31,6 +31,10 @@ FactoryBot.define do
user_type { :project_bot }
end
+ trait :migration_bot do
+ user_type { :migration_bot }
+ end
+
trait :external do
external { true }
end
@@ -40,7 +44,7 @@ FactoryBot.define do
end
trait :ghost do
- ghost { true }
+ user_type { :ghost }
after(:build) { |user, _| user.block! }
end
diff --git a/spec/factories/wiki_pages.rb b/spec/factories/wiki_pages.rb
index 8eb7a12a928..e7fcc19bbfe 100644
--- a/spec/factories/wiki_pages.rb
+++ b/spec/factories/wiki_pages.rb
@@ -7,10 +7,17 @@ FactoryBot.define do
transient do
title { generate(:wiki_page_title) }
content { 'Content for wiki page' }
- format { 'markdown' }
- project { create(:project) }
- attrs do
- {
+ format { :markdown }
+ message { nil }
+ project { association(:project, :wiki_repo) }
+ container { project }
+ wiki { association(:wiki, container: container) }
+ page { OpenStruct.new(url_path: title) }
+ end
+
+ initialize_with do
+ new(wiki, page).tap do |page|
+ page.attributes = {
title: title,
content: content,
format: format
@@ -18,27 +25,13 @@ FactoryBot.define do
end
end
- page { OpenStruct.new(url_path: 'some-name') }
- wiki { build(:project_wiki, project: project) }
-
- initialize_with { new(wiki, page) }
-
- before(:create) do |page, evaluator|
- page.attributes = evaluator.attrs
- end
-
- to_create do |page|
- page.create
+ # Clear our default @page, except when using build_stubbed
+ after(:build) do |page|
+ page.instance_variable_set('@page', nil)
end
- trait :with_real_page do
- project { create(:project, :repository) }
-
- page do
- wiki.create_page(title, content)
- page_title, page_dir = wiki.page_title_and_dir(title)
- wiki.wiki.page(title: page_title, dir: page_dir, version: nil)
- end
+ to_create do |page, evaluator|
+ page.create(message: evaluator.message)
end
end
@@ -48,10 +41,10 @@ FactoryBot.define do
trait :for_wiki_page do
transient do
- wiki_page { create(:wiki_page, project: project) }
+ wiki_page { create(:wiki_page, container: project) }
end
- project { @overrides[:wiki_page]&.project || create(:project) }
+ project { @overrides[:wiki_page]&.container || create(:project) }
title { wiki_page.title }
initialize_with do
@@ -73,5 +66,6 @@ FactoryBot.define do
end
sequence(:wiki_page_title) { |n| "Page #{n}" }
+ sequence(:wiki_filename) { |n| "Page_#{n}.md" }
sequence(:sluggified_title) { |n| "slug-#{n}" }
end
diff --git a/spec/factories/wikis.rb b/spec/factories/wikis.rb
new file mode 100644
index 00000000000..96578fdcee6
--- /dev/null
+++ b/spec/factories/wikis.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :wiki do
+ transient do
+ container { association(:project, :wiki_repo) }
+ user { association(:user) }
+ end
+
+ initialize_with { Wiki.for_container(container, user) }
+ skip_create
+
+ factory :project_wiki do
+ transient do
+ project { association(:project, :wiki_repo) }
+ end
+
+ container { project }
+ end
+ end
+end