diff options
Diffstat (limited to 'spec/factories')
31 files changed, 159 insertions, 17 deletions
diff --git a/spec/factories/achievements/achievements.rb b/spec/factories/achievements/achievements.rb new file mode 100644 index 00000000000..080a0376999 --- /dev/null +++ b/spec/factories/achievements/achievements.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :achievement, class: 'Achievements::Achievement' do + namespace + + name { generate(:name) } + end +end diff --git a/spec/factories/bulk_import.rb b/spec/factories/bulk_import.rb index 748afc0c67c..54d05264269 100644 --- a/spec/factories/bulk_import.rb +++ b/spec/factories/bulk_import.rb @@ -5,6 +5,7 @@ FactoryBot.define do user source_type { :gitlab } source_version { BulkImport.min_gl_version_for_project_migration.to_s } + source_enterprise { false } trait :created do status { 0 } diff --git a/spec/factories/bulk_import/trackers.rb b/spec/factories/bulk_import/trackers.rb index 22e0aa096fc..3e69ab26801 100644 --- a/spec/factories/bulk_import/trackers.rb +++ b/spec/factories/bulk_import/trackers.rb @@ -7,23 +7,22 @@ FactoryBot.define do stage { 0 } has_next_page { false } sequence(:pipeline_name) { |n| "pipeline_name_#{n}" } + sequence(:jid) { |n| "bulk_import_entity_#{n}" } trait :started do status { 1 } - - sequence(:jid) { |n| "bulk_import_entity_#{n}" } end trait :finished do status { 2 } - - sequence(:jid) { |n| "bulk_import_entity_#{n}" } end trait :failed do status { -1 } + end - sequence(:jid) { |n| "bulk_import_entity_#{n}" } + trait :skipped do + status { -2 } end end end diff --git a/spec/factories/ci/build_runner_sessions.rb b/spec/factories/ci/build_runner_sessions.rb new file mode 100644 index 00000000000..f78eaa6a5f1 --- /dev/null +++ b/spec/factories/ci/build_runner_sessions.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ci_build_runner_session, class: 'Ci::BuildRunnerSession' do + build factory: :ci_build + url { 'https://gitlab.example.com' } + end +end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index b88d6b5fda4..15a88955e05 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -7,6 +7,7 @@ FactoryBot.define do created_at { 'Di 29. Okt 09:50:00 CET 2013' } scheduling_type { 'stage' } pending + partition_id { pipeline.partition_id } options do { @@ -24,6 +25,8 @@ FactoryBot.define do project { pipeline.project } + ref { pipeline.ref } + trait :with_token do transient do generate_token { true } @@ -545,9 +548,12 @@ FactoryBot.define do options do { image: { name: 'image:1.0', entrypoint: '/bin/sh' }, - services: ['postgres', { name: 'docker:stable-dind', entrypoint: '/bin/sh', command: 'sleep 30', alias: 'docker' }, { name: 'mysql:latest', variables: { MYSQL_ROOT_PASSWORD: 'root123.' } }], + services: ['postgres', + { name: 'docker:stable-dind', entrypoint: '/bin/sh', command: 'sleep 30', alias: 'docker' }, + { name: 'mysql:latest', variables: { MYSQL_ROOT_PASSWORD: 'root123.' } }], script: %w(echo), after_script: %w(ls date), + hooks: { pre_get_sources_script: ["echo 'hello pre_get_sources_script'"] }, artifacts: { name: 'artifacts_file', untracked: false, diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb index 891628a0fc2..eef5c593e0f 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -8,7 +8,7 @@ FactoryBot.define do sha { 'b83d6e391c22777fca1ed3012fce84f633d7fed0' } status { 'pending' } add_attribute(:protected) { false } - partition_id { 100 } + partition_id { Ci::Pipeline.current_partition_value } project @@ -54,7 +54,6 @@ FactoryBot.define do end factory :ci_pipeline do - partition_id { 100 } transient { ci_ref_presence { true } } before(:create) do |pipeline, evaluator| @@ -84,6 +83,7 @@ FactoryBot.define do end trait :running do + started_at { Time.current } status { :running } end diff --git a/spec/factories/ci/resource.rb b/spec/factories/ci/resource.rb index dec26013a25..946cf9c17a7 100644 --- a/spec/factories/ci/resource.rb +++ b/spec/factories/ci/resource.rb @@ -6,6 +6,7 @@ FactoryBot.define do trait(:retained) do processable factory: :ci_build + partition_id { processable.partition_id } end end end diff --git a/spec/factories/ci/sources/pipelines.rb b/spec/factories/ci/sources/pipelines.rb index 93d35097eac..bfe487eb6bb 100644 --- a/spec/factories/ci/sources/pipelines.rb +++ b/spec/factories/ci/sources/pipelines.rb @@ -4,8 +4,8 @@ FactoryBot.define do factory :ci_sources_pipeline, class: 'Ci::Sources::Pipeline' do after(:build) do |source| source.project ||= source.pipeline.project - source.source_pipeline ||= source.source_job.pipeline - source.source_project ||= source.source_pipeline.project + source.source_pipeline ||= source.source_job&.pipeline + source.source_project ||= source.source_pipeline&.project end source_job factory: :ci_build diff --git a/spec/factories/ci/unit_test_failure.rb b/spec/factories/ci/unit_test_failures.rb index 07cd3419754..07cd3419754 100644 --- a/spec/factories/ci/unit_test_failure.rb +++ b/spec/factories/ci/unit_test_failures.rb diff --git a/spec/factories/ci/unit_test.rb b/spec/factories/ci/unit_tests.rb index 480724f260a..480724f260a 100644 --- a/spec/factories/ci/unit_test.rb +++ b/spec/factories/ci/unit_tests.rb diff --git a/spec/factories/clusters/agents/group_authorizations.rb b/spec/factories/clusters/agents/group_authorizations.rb index 6ea3668dc66..abe25794234 100644 --- a/spec/factories/clusters/agents/group_authorizations.rb +++ b/spec/factories/clusters/agents/group_authorizations.rb @@ -5,6 +5,14 @@ FactoryBot.define do association :agent, factory: :cluster_agent group - config { { default_namespace: 'production' } } + transient do + environments { nil } + end + + config do + { default_namespace: 'production' }.tap do |c| + c[:environments] = environments if environments + end + end end end diff --git a/spec/factories/clusters/agents/project_authorizations.rb b/spec/factories/clusters/agents/project_authorizations.rb index 176ecc3b517..eecbfe95bfc 100644 --- a/spec/factories/clusters/agents/project_authorizations.rb +++ b/spec/factories/clusters/agents/project_authorizations.rb @@ -5,6 +5,14 @@ FactoryBot.define do association :agent, factory: :cluster_agent project - config { { default_namespace: 'production' } } + transient do + environments { nil } + end + + config do + { default_namespace: 'production' }.tap do |c| + c[:environments] = environments if environments + end + end end end diff --git a/spec/factories/dependency_proxy.rb b/spec/factories/dependency_proxy.rb index 33356a701df..43cc923a4c5 100644 --- a/spec/factories/dependency_proxy.rb +++ b/spec/factories/dependency_proxy.rb @@ -23,14 +23,21 @@ FactoryBot.define do factory :dependency_proxy_manifest, class: 'DependencyProxy::Manifest' do group size { 1234 } - file { fixture_file_upload('spec/fixtures/dependency_proxy/manifest') } digest { 'sha256:d0710affa17fad5f466a70159cc458227bd25d4afb39514ef662ead3e6c99515' } sequence(:file_name) { |n| "alpine:latest#{n}.json" } content_type { 'application/vnd.docker.distribution.manifest.v2+json' } status { :default } + after(:build) do |manifest, _evaluator| + manifest.file = fixture_file_upload('spec/fixtures/dependency_proxy/manifest') + end + trait :pending_destruction do status { :pending_destruction } end + + trait :remote_store do + file_store { DependencyProxy::FileUploader::Store::REMOTE } + end end end diff --git a/spec/factories/deploy_tokens.rb b/spec/factories/deploy_tokens.rb index a2116b738fd..45e92869e22 100644 --- a/spec/factories/deploy_tokens.rb +++ b/spec/factories/deploy_tokens.rb @@ -10,7 +10,7 @@ FactoryBot.define do read_package_registry { false } write_package_registry { false } revoked { false } - expires_at { 5.days.from_now } + expires_at { 5.days.from_now.to_datetime } deploy_token_type { DeployToken.deploy_token_types[:project_type] } trait :revoked do diff --git a/spec/factories/events.rb b/spec/factories/events.rb index a4f06a48621..0f564afe822 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -64,6 +64,11 @@ FactoryBot.define do target_type { 'WorkItem' } end + trait :for_merge_request do + target { association(:merge_request) } + target_type { 'MergeRequest' } + end + factory :design_event, traits: [:has_design] do action { :created } target { design } diff --git a/spec/factories/groups.rb b/spec/factories/groups.rb index 6f9cf0ef895..f4d47b9ff8c 100644 --- a/spec/factories/groups.rb +++ b/spec/factories/groups.rb @@ -118,5 +118,9 @@ FactoryBot.define do create(:crm_settings, group: group, enabled: true) end end + + trait :with_root_storage_statistics do + association :root_storage_statistics, factory: :namespace_root_storage_statistics + end end end diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index 88522737e06..70a4a3ec822 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -4,6 +4,7 @@ FactoryBot.define do factory :issue, traits: [:has_internal_id] do title { generate(:title) } project + namespace { project.project_namespace } author { project.creator } updated_by { author } relative_position { RelativePositioning::START_POSITION } @@ -70,6 +71,16 @@ FactoryBot.define do association :work_item_type, :default, :task end + trait :objective do + issue_type { :objective } + association :work_item_type, :default, :objective + end + + trait :key_result do + issue_type { :key_result } + association :work_item_type, :default, :key_result + end + factory :incident do issue_type { :incident } association :work_item_type, :default, :incident diff --git a/spec/factories/ml/candidate_metadata.rb b/spec/factories/ml/candidate_metadata.rb new file mode 100644 index 00000000000..e941ae4deb8 --- /dev/null +++ b/spec/factories/ml/candidate_metadata.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ml_candidate_metadata, class: '::Ml::CandidateMetadata' do + association :candidate, factory: :ml_candidates + + sequence(:name) { |n| "metadata_#{n}" } + sequence(:value) { |n| "value#{n}" } + end +end diff --git a/spec/factories/ml/candidates.rb b/spec/factories/ml/candidates.rb index 4fbcdc46103..2daed36d777 100644 --- a/spec/factories/ml/candidates.rb +++ b/spec/factories/ml/candidates.rb @@ -10,5 +10,11 @@ FactoryBot.define do candidate.params = FactoryBot.create_list(:ml_candidate_params, 2, candidate: candidate ) end end + + trait :with_metadata do + after(:create) do |candidate| + candidate.metadata = FactoryBot.create_list(:ml_candidate_metadata, 2, candidate: candidate ) + end + end end end diff --git a/spec/factories/ml/experiment_metadata.rb b/spec/factories/ml/experiment_metadata.rb new file mode 100644 index 00000000000..d3ece9630a4 --- /dev/null +++ b/spec/factories/ml/experiment_metadata.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ml_experiment_metadata, class: '::Ml::ExperimentMetadata' do + association :experiment, factory: :ml_experiments + + sequence(:name) { |n| "metadata_#{n}" } + sequence(:value) { |n| "value#{n}" } + end +end diff --git a/spec/factories/ml/experiments.rb b/spec/factories/ml/experiments.rb index e4f5a0da6cf..0acb4c5c5fc 100644 --- a/spec/factories/ml/experiments.rb +++ b/spec/factories/ml/experiments.rb @@ -4,6 +4,12 @@ FactoryBot.define do sequence(:name) { |n| "experiment#{n}" } project - user + user { project&.creator } + + trait :with_metadata do + after(:create) do |e| + e.metadata = FactoryBot.create_list(:ml_experiment_metadata, 2, experiment: e) # rubocop:disable StrategyInCallback + end + end end end diff --git a/spec/factories/packages/rpm/rpm_repository_files.rb b/spec/factories/packages/rpm/rpm_repository_files.rb index 00755f49d98..7b86c593627 100644 --- a/spec/factories/packages/rpm/rpm_repository_files.rb +++ b/spec/factories/packages/rpm/rpm_repository_files.rb @@ -34,5 +34,9 @@ FactoryBot.define do trait :pending_destruction do status { :pending_destruction } end + + trait :filelists do + file_name { 'filelists.xml' } + end end end diff --git a/spec/factories/project_export_jobs.rb b/spec/factories/project_export_jobs.rb index b2666555ea8..bf8cfd863ec 100644 --- a/spec/factories/project_export_jobs.rb +++ b/spec/factories/project_export_jobs.rb @@ -4,5 +4,21 @@ FactoryBot.define do factory :project_export_job do project jid { SecureRandom.hex(8) } + + trait :queued do + status { ProjectExportJob::STATUS[:queued] } + end + + trait :started do + status { ProjectExportJob::STATUS[:started] } + end + + trait :finished do + status { ProjectExportJob::STATUS[:finished] } + end + + trait :failed do + status { ProjectExportJob::STATUS[:failed] } + end end end diff --git a/spec/factories/projects/ci_feature_usages.rb b/spec/factories/projects/ci_feature_usages.rb index 1ab1d82ef4b..48e5331afcc 100644 --- a/spec/factories/projects/ci_feature_usages.rb +++ b/spec/factories/projects/ci_feature_usages.rb @@ -4,6 +4,7 @@ FactoryBot.define do factory :project_ci_feature_usage, class: 'Projects::CiFeatureUsage' do project factory: :project feature { :code_coverage } # rubocop: disable RSpec/EmptyExampleGroup + default_branch { false } end end diff --git a/spec/factories/projects/import_export/relation_export_upload.rb b/spec/factories/projects/import_export/relation_export_upload.rb index eaa57d6ee59..4bd6a586720 100644 --- a/spec/factories/projects/import_export/relation_export_upload.rb +++ b/spec/factories/projects/import_export/relation_export_upload.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true FactoryBot.define do - factory :project_relation_export_upload, class: 'Projects::ImportExport::RelationExportUpload' do + factory :relation_export_upload, class: 'Projects::ImportExport::RelationExportUpload' do relation_export factory: :project_relation_export export_file { fixture_file_upload("spec/fixtures/gitlab/import_export/labels.tar.gz") } end diff --git a/spec/factories/resource_milestone_event.rb b/spec/factories/resource_milestone_events.rb index a3944e013da..a3944e013da 100644 --- a/spec/factories/resource_milestone_event.rb +++ b/spec/factories/resource_milestone_events.rb diff --git a/spec/factories/resource_state_event.rb b/spec/factories/resource_state_events.rb index 926c6dd8cbc..926c6dd8cbc 100644 --- a/spec/factories/resource_state_event.rb +++ b/spec/factories/resource_state_events.rb diff --git a/spec/factories/todos.rb b/spec/factories/todos.rb index 97a1265c46a..760367539fc 100644 --- a/spec/factories/todos.rb +++ b/spec/factories/todos.rb @@ -41,6 +41,10 @@ FactoryBot.define do action { Todo::UNMERGEABLE } end + trait :member_access_requested do + action { Todo::MEMBER_ACCESS_REQUESTED } + end + trait :pending do state { :pending } end diff --git a/spec/factories/work_items.rb b/spec/factories/work_items.rb index 205b071a5d4..cff246d4071 100644 --- a/spec/factories/work_items.rb +++ b/spec/factories/work_items.rb @@ -27,5 +27,15 @@ FactoryBot.define do trait :last_edited_by_user do association :last_edited_by, factory: :user end + + trait :objective do + issue_type { :objective } + association :work_item_type, :default, :objective + end + + trait :key_result do + issue_type { :key_result } + association :work_item_type, :default, :key_result + end end end diff --git a/spec/factories/work_items/hierarchy_restrictions.rb b/spec/factories/work_items/hierarchy_restrictions.rb new file mode 100644 index 00000000000..09a10b633ba --- /dev/null +++ b/spec/factories/work_items/hierarchy_restrictions.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :hierarchy_restriction, class: 'WorkItems::HierarchyRestriction' do + parent_type { association :work_item_type, :default } + child_type { association :work_item_type, :default } + end +end diff --git a/spec/factories/work_items/work_item_types.rb b/spec/factories/work_items/work_item_types.rb index 1b6137503d3..d36cb6260c6 100644 --- a/spec/factories/work_items/work_item_types.rb +++ b/spec/factories/work_items/work_item_types.rb @@ -13,7 +13,7 @@ FactoryBot.define do # Expect base_types to exist on the DB if type_base_attributes.slice(:namespace, :namespace_id).compact.empty? - WorkItems::Type.find_or_initialize_by(type_base_attributes).tap { |type| type.assign_attributes(attributes) } + WorkItems::Type.find_or_initialize_by(type_base_attributes) else WorkItems::Type.new(attributes) end |