diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/factories | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) | |
download | gitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/factories')
48 files changed, 361 insertions, 94 deletions
diff --git a/spec/factories/alert_management/http_integrations.rb b/spec/factories/alert_management/http_integrations.rb index 9311cb3e114..2b5864c8587 100644 --- a/spec/factories/alert_management/http_integrations.rb +++ b/spec/factories/alert_management/http_integrations.rb @@ -10,5 +10,11 @@ FactoryBot.define do trait :inactive do active { false } end + + trait :legacy do + endpoint_identifier { 'legacy' } + end + + initialize_with { new(**attributes) } end end diff --git a/spec/factories/alerts_service_data.rb b/spec/factories/alerts_service_data.rb new file mode 100644 index 00000000000..2dd1d0a714e --- /dev/null +++ b/spec/factories/alerts_service_data.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :alerts_service_data do + service { association(:alerts_service) } + token { SecureRandom.hex } + end +end diff --git a/spec/factories/analytics/devops_adoption/segment_selections.rb b/spec/factories/analytics/devops_adoption/segment_selections.rb new file mode 100644 index 00000000000..8f10369ba35 --- /dev/null +++ b/spec/factories/analytics/devops_adoption/segment_selections.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :devops_adoption_segment_selection, class: 'Analytics::DevopsAdoption::SegmentSelection' do + association :segment, factory: :devops_adoption_segment + project + + trait :project do + group { nil } + project + end + + trait :group do + project { nil } + group + end + end +end diff --git a/spec/factories/analytics/devops_adoption/segments.rb b/spec/factories/analytics/devops_adoption/segments.rb new file mode 100644 index 00000000000..367ee01fa18 --- /dev/null +++ b/spec/factories/analytics/devops_adoption/segments.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :devops_adoption_segment, class: 'Analytics::DevopsAdoption::Segment' do + sequence(:name) { |n| "Segment #{n}" } + end +end diff --git a/spec/factories/instance_statistics/measurement.rb b/spec/factories/analytics/instance_statistics/measurement.rb index f9398cd3061..f9398cd3061 100644 --- a/spec/factories/instance_statistics/measurement.rb +++ b/spec/factories/analytics/instance_statistics/measurement.rb diff --git a/spec/factories/audit_events.rb b/spec/factories/audit_events.rb index 5497648273c..4e72976a9e5 100644 --- a/spec/factories/audit_events.rb +++ b/spec/factories/audit_events.rb @@ -4,7 +4,7 @@ FactoryBot.define do factory :audit_event, class: 'AuditEvent', aliases: [:user_audit_event] do user - transient { target_user { create(:user) } } + transient { target_user { association(:user) } } entity_type { 'User' } entity_id { target_user.id } @@ -27,7 +27,7 @@ FactoryBot.define do end trait :project_event do - transient { target_project { create(:project) } } + transient { target_project { association(:project) } } entity_type { 'Project' } entity_id { target_project.id } @@ -50,7 +50,7 @@ FactoryBot.define do end trait :group_event do - transient { target_group { create(:group) } } + transient { target_group { association(:group) } } entity_type { 'Group' } entity_id { target_group.id } diff --git a/spec/factories/bulk_import.rb b/spec/factories/bulk_import.rb index 0231fe7cfef..07907bab3df 100644 --- a/spec/factories/bulk_import.rb +++ b/spec/factories/bulk_import.rb @@ -4,5 +4,21 @@ FactoryBot.define do factory :bulk_import, class: 'BulkImport' do user source_type { :gitlab } + + trait :created do + status { 0 } + end + + trait :started do + status { 1 } + end + + trait :finished do + status { 2 } + end + + trait :failed do + status { -1 } + end end end diff --git a/spec/factories/bulk_import/entities.rb b/spec/factories/bulk_import/entities.rb index 3bf6af92d00..cf31ffec4f6 100644 --- a/spec/factories/bulk_import/entities.rb +++ b/spec/factories/bulk_import/entities.rb @@ -17,5 +17,25 @@ FactoryBot.define do trait(:project_entity) do source_type { :project_entity } end + + trait :created do + status { 0 } + end + + 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 end end diff --git a/spec/factories/bulk_import/trackers.rb b/spec/factories/bulk_import/trackers.rb new file mode 100644 index 00000000000..7a1fa0849fc --- /dev/null +++ b/spec/factories/bulk_import/trackers.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :bulk_import_tracker, class: 'BulkImports::Tracker' do + association :entity, factory: :bulk_import_entity + + relation { :relation } + has_next_page { false } + end +end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 73920b76025..11719e40cf2 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -332,6 +332,18 @@ FactoryBot.define do end end + trait :test_reports_with_duplicate_failed_test_names do + after(:build) do |build| + build.job_artifacts << create(:ci_job_artifact, :junit_with_duplicate_failed_test_names, job: build) + end + end + + trait :test_reports_with_three_failures do + after(:build) do |build| + build.job_artifacts << create(:ci_job_artifact, :junit_with_three_failures, job: build) + end + end + trait :accessibility_reports do after(:build) do |build| build.job_artifacts << create(:ci_job_artifact, :accessibility, job: build) @@ -492,10 +504,21 @@ FactoryBot.define do failure_reason { 10 } end + trait :forward_deployment_failure do + failed + failure_reason { 13 } + end + trait :with_runner_session do after(:build) do |build| build.build_runner_session(url: 'https://localhost') end end + + trait :interruptible do + after(:build) do |build| + build.metadata.interruptible = true + end + end end end diff --git a/spec/factories/ci/daily_build_group_report_results.rb b/spec/factories/ci/daily_build_group_report_results.rb index 8653316b51a..d836ee9567c 100644 --- a/spec/factories/ci/daily_build_group_report_results.rb +++ b/spec/factories/ci/daily_build_group_report_results.rb @@ -3,12 +3,18 @@ FactoryBot.define 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 } + date { Date.current } project last_pipeline factory: :ci_pipeline group_name { 'rspec' } data do { 'coverage' => 77.0 } end + default_branch { true } + + trait :on_feature_branch do + ref_path { Gitlab::Git::BRANCH_REF_PREFIX + 'feature' } + default_branch { false } + end end end diff --git a/spec/factories/ci/job_artifacts.rb b/spec/factories/ci/job_artifacts.rb index 1bd4b2826c4..223184891b7 100644 --- a/spec/factories/ci/job_artifacts.rb +++ b/spec/factories/ci/job_artifacts.rb @@ -109,6 +109,16 @@ FactoryBot.define do end end + trait :junit_with_duplicate_failed_test_names do + file_type { :junit } + file_format { :gzip } + + after(:build) do |artifact, evaluator| + artifact.file = fixture_file_upload( + Rails.root.join('spec/fixtures/junit/junit_with_duplicate_failed_test_names.xml.gz'), 'application/x-gzip') + end + end + trait :junit_with_ant do file_type { :junit } file_format { :gzip } @@ -139,6 +149,16 @@ FactoryBot.define do end end + trait :junit_with_three_failures do + file_type { :junit } + file_format { :gzip } + + after(:build) do |artifact, evaluator| + artifact.file = fixture_file_upload( + Rails.root.join('spec/fixtures/junit/junit_with_three_failures.xml.gz'), 'application/x-gzip') + end + end + trait :accessibility do file_type { :accessibility } file_format { :raw } diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb index 4fa5dde4eff..14bd0ab1bc6 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -121,6 +121,14 @@ FactoryBot.define do end end + trait :with_test_reports_with_three_failures do + status { :success } + + after(:build) do |pipeline, _evaluator| + pipeline.builds << build(:ci_build, :test_reports_with_three_failures, pipeline: pipeline, project: pipeline.project) + end + end + trait :with_accessibility_reports do status { :success } diff --git a/spec/factories/ci/reports/test_case.rb b/spec/factories/ci/reports/test_case.rb new file mode 100644 index 00000000000..0626de9d6dc --- /dev/null +++ b/spec/factories/ci/reports/test_case.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :report_test_case, class: 'Gitlab::Ci::Reports::TestCase' do + suite_name { "rspec" } + name { "test-1" } + classname { "trace" } + file { "spec/trace_spec.rb" } + execution_time { 1.23 } + status { Gitlab::Ci::Reports::TestCase::STATUS_SUCCESS } + system_output { nil } + attachment { nil } + association :job, factory: :ci_build + + trait :failed do + status { Gitlab::Ci::Reports::TestCase::STATUS_FAILED } + system_output { "Failure/Error: is_expected.to eq(300) expected: 300 got: -100" } + end + + trait :failed_with_attachment do + status { Gitlab::Ci::Reports::TestCase::STATUS_FAILED } + attachment { "some/path.png" } + end + + skip_create + + initialize_with do + new( + suite_name: suite_name, + name: name, + classname: classname, + file: file, + execution_time: execution_time, + status: status, + system_output: system_output, + attachment: attachment, + job: job + ) + end + end +end diff --git a/spec/factories/ci/test_case.rb b/spec/factories/ci/test_case.rb index 7f99f0e123e..601a3fae970 100644 --- a/spec/factories/ci/test_case.rb +++ b/spec/factories/ci/test_case.rb @@ -1,41 +1,8 @@ # frozen_string_literal: true FactoryBot.define do - factory :test_case, class: 'Gitlab::Ci::Reports::TestCase' do - suite_name { "rspec" } - name { "test-1" } - classname { "trace" } - file { "spec/trace_spec.rb" } - execution_time { 1.23 } - status { Gitlab::Ci::Reports::TestCase::STATUS_SUCCESS } - system_output { nil } - attachment { nil } - association :job, factory: :ci_build - - trait :failed do - status { Gitlab::Ci::Reports::TestCase::STATUS_FAILED } - system_output { "Failure/Error: is_expected.to eq(300) expected: 300 got: -100" } - end - - trait :failed_with_attachment do - status { Gitlab::Ci::Reports::TestCase::STATUS_FAILED } - attachment { "some/path.png" } - end - - skip_create - - initialize_with do - new( - suite_name: suite_name, - name: name, - classname: classname, - file: file, - execution_time: execution_time, - status: status, - system_output: system_output, - attachment: attachment, - job: job - ) - end + factory :ci_test_case, class: 'Ci::TestCase' do + project + key_hash { Digest::SHA256.hexdigest(SecureRandom.hex) } end end diff --git a/spec/factories/ci/test_case_failure.rb b/spec/factories/ci/test_case_failure.rb new file mode 100644 index 00000000000..11fb002804b --- /dev/null +++ b/spec/factories/ci/test_case_failure.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ci_test_case_failure, class: 'Ci::TestCaseFailure' do + build factory: :ci_build + test_case factory: :ci_test_case + failed_at { Time.current } + end +end diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb index 46aa640780b..01df5cc677d 100644 --- a/spec/factories/clusters/applications/helm.rb +++ b/spec/factories/clusters/applications/helm.rb @@ -5,7 +5,7 @@ FactoryBot.define do cluster factory: %i(cluster provided_by_gcp) before(:create) do - allow(Gitlab::Kubernetes::Helm::Certificate).to receive(:generate_root) + allow(Gitlab::Kubernetes::Helm::V2::Certificate).to receive(:generate_root) .and_return( double( key_string: File.read(Rails.root.join('spec/fixtures/clusters/sample_key.key')), @@ -15,7 +15,7 @@ FactoryBot.define do end after(:create) do - allow(Gitlab::Kubernetes::Helm::Certificate).to receive(:generate_root).and_call_original + allow(Gitlab::Kubernetes::Helm::V2::Certificate).to receive(:generate_root).and_call_original end trait :not_installable do diff --git a/spec/factories/container_repositories.rb b/spec/factories/container_repositories.rb index 4cf1537f64b..86bb129067f 100644 --- a/spec/factories/container_repositories.rb +++ b/spec/factories/container_repositories.rb @@ -13,6 +13,26 @@ FactoryBot.define do name { '' } end + trait :status_delete_scheduled do + status { :delete_scheduled } + end + + trait :status_delete_failed do + status { :delete_failed } + end + + trait :cleanup_scheduled do + expiration_policy_cleanup_status { :cleanup_scheduled } + end + + trait :cleanup_unfinished do + expiration_policy_cleanup_status { :cleanup_unfinished } + end + + trait :cleanup_ongoing do + expiration_policy_cleanup_status { :cleanup_ongoing } + end + after(:build) do |repository, evaluator| next if evaluator.tags.to_a.none? diff --git a/spec/factories/custom_emoji.rb b/spec/factories/custom_emoji.rb index 2d185794ac9..ba1ae11c18d 100644 --- a/spec/factories/custom_emoji.rb +++ b/spec/factories/custom_emoji.rb @@ -4,6 +4,7 @@ FactoryBot.define do factory :custom_emoji, class: 'CustomEmoji' do sequence(:name) { |n| "custom_emoji#{n}" } namespace - file { fixture_file_upload(Rails.root.join('spec/fixtures/dk.png')) } + group + file { 'https://gitlab.com/images/partyparrot.png' } end end diff --git a/spec/factories/dependency_proxy.rb b/spec/factories/dependency_proxy.rb new file mode 100644 index 00000000000..5d763392a99 --- /dev/null +++ b/spec/factories/dependency_proxy.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :dependency_proxy_blob, class: 'DependencyProxy::Blob' do + group + file { fixture_file_upload('spec/fixtures/dependency_proxy/a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4.gz') } + file_name { 'a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4.gz' } + end +end diff --git a/spec/factories/design_management/design_at_version.rb b/spec/factories/design_management/design_at_version.rb index b73df71595c..3d85269ee27 100644 --- a/spec/factories/design_management/design_at_version.rb +++ b/spec/factories/design_management/design_at_version.rb @@ -9,13 +9,13 @@ FactoryBot.define do version { nil } transient do - issue { design&.issue || version&.issue || create(:issue) } + issue { design&.issue || version&.issue || association(:issue) } end initialize_with do attrs = attributes.dup - attrs[:design] ||= create(:design, issue: issue) - attrs[:version] ||= create(:design_version, issue: issue) + attrs[:design] ||= association(:design, issue: issue) + attrs[:version] ||= association(:design_version, issue: issue) new(attrs) end diff --git a/spec/factories/design_management/designs.rb b/spec/factories/design_management/designs.rb index 38d0545483c..c4fb330a0da 100644 --- a/spec/factories/design_management/designs.rb +++ b/spec/factories/design_management/designs.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true FactoryBot.define do - factory :design, class: 'DesignManagement::Design' do - issue { create(:issue) } - project { issue&.project || create(:project) } + factory :design, traits: [:has_internal_id], class: 'DesignManagement::Design' do + issue { association(:issue) } + project { issue&.project || association(:project) } sequence(:filename) { |n| "homescreen-#{n}.jpg" } transient do diff --git a/spec/factories/design_management/versions.rb b/spec/factories/design_management/versions.rb index a5c0e7076e9..0233a3b567d 100644 --- a/spec/factories/design_management/versions.rb +++ b/spec/factories/design_management/versions.rb @@ -3,8 +3,8 @@ FactoryBot.define do factory :design_version, class: 'DesignManagement::Version' do sha - issue { designs.first&.issue || create(:issue) } - author { issue&.author || create(:user) } + issue { designs.first&.issue || association(:issue) } + author { issue&.author || association(:user) } transient do designs_count { 1 } diff --git a/spec/factories/import_configurations.rb b/spec/factories/import_configurations.rb new file mode 100644 index 00000000000..1686d1b0d75 --- /dev/null +++ b/spec/factories/import_configurations.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :bulk_import_configuration, class: 'BulkImports::Configuration' do + association :bulk_import, factory: :bulk_import + + url { 'https://gitlab.example' } + access_token { 'token' } + end +end diff --git a/spec/factories/issues/csv_import.rb b/spec/factories/issues/csv_import.rb new file mode 100644 index 00000000000..94688cf6232 --- /dev/null +++ b/spec/factories/issues/csv_import.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :issue_csv_import, class: 'Issues::CsvImport' do + project + user + end +end diff --git a/spec/factories/merge_request_cleanup_schedules.rb b/spec/factories/merge_request_cleanup_schedules.rb new file mode 100644 index 00000000000..a89d0c88731 --- /dev/null +++ b/spec/factories/merge_request_cleanup_schedules.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :merge_request_cleanup_schedule, class: 'MergeRequest::CleanupSchedule' do + merge_request + scheduled_at { Time.current } + end +end diff --git a/spec/factories/packages.rb b/spec/factories/packages.rb index e2c5b000988..73870a28b89 100644 --- a/spec/factories/packages.rb +++ b/spec/factories/packages.rb @@ -129,7 +129,7 @@ FactoryBot.define do end trait(:without_loaded_metadatum) do - conan_metadatum { build(:conan_metadatum, package: nil) } + conan_metadatum { build(:conan_metadatum, package: nil) } # rubocop:disable FactoryBot/InlineAssociation end end @@ -141,16 +141,12 @@ FactoryBot.define do end factory :composer_metadatum, class: 'Packages::Composer::Metadatum' do - package { create(:composer_package) } + package { association(:composer_package) } target_sha { '123' } composer_json { { name: 'foo' } } end - factory :package_build_info, class: 'Packages::BuildInfo' do - package - end - factory :maven_metadatum, class: 'Packages::Maven::Metadatum' do association :package, package_type: :maven path { 'my/company/app/my-app/1.0-SNAPSHOT' } @@ -166,12 +162,12 @@ FactoryBot.define do end factory :pypi_metadatum, class: 'Packages::Pypi::Metadatum' do - package { create(:pypi_package, without_loaded_metadatum: true) } + package { association(:pypi_package, without_loaded_metadatum: true) } required_python { '>=2.7' } end factory :nuget_metadatum, class: 'Packages::Nuget::Metadatum' do - package { create(:nuget_package) } + package { association(:nuget_package) } license_url { 'http://www.gitlab.com' } project_url { 'http://www.gitlab.com' } @@ -179,7 +175,7 @@ FactoryBot.define do end factory :conan_file_metadatum, class: 'Packages::Conan::FileMetadatum' do - package_file { create(:conan_package_file, :conan_recipe_file, without_loaded_metadatum: true) } + package_file { association(:conan_package_file, :conan_recipe_file, without_loaded_metadatum: true) } recipe_revision { '0' } conan_file_type { 'recipe_file' } @@ -188,7 +184,7 @@ FactoryBot.define do end trait(:package_file) do - package_file { create(:conan_package_file, :conan_package, without_loaded_metadatum: true) } + package_file { association(:conan_package_file, :conan_package, without_loaded_metadatum: true) } conan_file_type { 'package_file' } package_revision { '0' } conan_package_reference { '123456789' } @@ -201,8 +197,8 @@ FactoryBot.define do end factory :packages_dependency_link, class: 'Packages::DependencyLink' do - package { create(:nuget_package) } - dependency { create(:packages_dependency) } + package { association(:nuget_package) } + dependency { association(:packages_dependency) } dependency_type { :dependencies } trait(:with_nuget_metadatum) do @@ -213,7 +209,7 @@ FactoryBot.define do end factory :nuget_dependency_link_metadatum, class: 'Packages::Nuget::DependencyLinkMetadatum' do - dependency_link { create(:packages_dependency_link) } + dependency_link { association(:packages_dependency_link) } target_framework { '.NETStandard2.0' } end diff --git a/spec/factories/packages/build_info.rb b/spec/factories/packages/build_info.rb new file mode 100644 index 00000000000..dc6208d72a9 --- /dev/null +++ b/spec/factories/packages/build_info.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :package_build_info, class: 'Packages::BuildInfo' do + package + + trait :with_pipeline do + association :pipeline, factory: [:ci_pipeline, :with_job] + end + end +end diff --git a/spec/factories/packages/package_file.rb b/spec/factories/packages/package_file.rb index bcca48fb086..643ab8e4f95 100644 --- a/spec/factories/packages/package_file.rb +++ b/spec/factories/packages/package_file.rb @@ -15,7 +15,7 @@ FactoryBot.define do end factory :conan_package_file do - package { create(:conan_package, without_package_files: true) } + package { association(:conan_package, without_package_files: true) } transient do without_loaded_metadatum { false } diff --git a/spec/factories/packages/package_file_build_infos.rb b/spec/factories/packages/package_file_build_infos.rb new file mode 100644 index 00000000000..f83c32f4a1a --- /dev/null +++ b/spec/factories/packages/package_file_build_infos.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :package_file_build_info, class: 'Packages::PackageFileBuildInfo' do + package_file + + trait :with_pipeline do + association :pipeline, factory: [:ci_pipeline, :with_job] + end + end +end diff --git a/spec/factories/pages_deployments.rb b/spec/factories/pages_deployments.rb index f57852a8f94..56aab4fa9f3 100644 --- a/spec/factories/pages_deployments.rb +++ b/spec/factories/pages_deployments.rb @@ -5,9 +5,13 @@ FactoryBot.define do project after(:build) do |deployment, _evaluator| - deployment.file = fixture_file_upload( - Rails.root.join("spec/fixtures/pages.zip") - ) + filepath = Rails.root.join("spec/fixtures/pages.zip") + + deployment.file = fixture_file_upload(filepath) + deployment.file_sha256 = Digest::SHA256.file(filepath).hexdigest + ::Zip::File.open(filepath) do |zip_archive| + deployment.file_count = zip_archive.count + end end end end diff --git a/spec/factories/project_hooks.rb b/spec/factories/project_hooks.rb index 15b240acba4..88c06b3857a 100644 --- a/spec/factories/project_hooks.rb +++ b/spec/factories/project_hooks.rb @@ -22,6 +22,8 @@ FactoryBot.define do pipeline_events { true } wiki_page_events { true } deployment_events { true } + feature_flag_events { true } + releases_events { true } end end end diff --git a/spec/factories/project_statistics.rb b/spec/factories/project_statistics.rb index ea003b67db0..ee2ad507c2d 100644 --- a/spec/factories/project_statistics.rb +++ b/spec/factories/project_statistics.rb @@ -23,6 +23,7 @@ FactoryBot.define do project_statistics.packages_size = evaluator.size_multiplier * 5 project_statistics.snippets_size = evaluator.size_multiplier * 6 project_statistics.pipeline_artifacts_size = evaluator.size_multiplier * 7 + project_statistics.uploads_size = evaluator.size_multiplier * 8 end end end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 87e4a8e355d..639fff06cec 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -10,8 +10,10 @@ FactoryBot.define do factory :project, class: 'Project' do sequence(:name) { |n| "project#{n}" } path { name.downcase.gsub(/\s/, '_') } - # Behaves differently to nil due to cache_has_external_issue_tracker + + # Behaves differently to nil due to cache_has_external_* methods. has_external_issue_tracker { false } + has_external_wiki { false } # Associations namespace diff --git a/spec/factories/protected_branches/push_access_levels.rb b/spec/factories/protected_branches/push_access_levels.rb index fa3a35fe282..b735bcdcc04 100644 --- a/spec/factories/protected_branches/push_access_levels.rb +++ b/spec/factories/protected_branches/push_access_levels.rb @@ -3,6 +3,7 @@ FactoryBot.define do factory :protected_branch_push_access_level, class: 'ProtectedBranch::PushAccessLevel' do protected_branch + deploy_key { nil } access_level { Gitlab::Access::DEVELOPER } end end diff --git a/spec/factories/resource_label_events.rb b/spec/factories/resource_label_events.rb index b59da465fc3..35c732fed0f 100644 --- a/spec/factories/resource_label_events.rb +++ b/spec/factories/resource_label_events.rb @@ -4,7 +4,7 @@ FactoryBot.define do factory :resource_label_event do action { :add } label - user { issuable&.author || create(:user) } + user { issuable&.author || association(:user) } after(:build) do |event, evaluator| event.issue = create(:issue) unless event.issuable diff --git a/spec/factories/resource_milestone_event.rb b/spec/factories/resource_milestone_event.rb index 86c54f2be68..a3944e013da 100644 --- a/spec/factories/resource_milestone_event.rb +++ b/spec/factories/resource_milestone_event.rb @@ -2,11 +2,11 @@ FactoryBot.define do factory :resource_milestone_event do - issue { merge_request.nil? ? create(:issue) : nil } + issue { merge_request.nil? ? association(:issue) : nil } merge_request { nil } milestone action { :add } state { :opened } - user { issue&.author || merge_request&.author || create(:user) } + user { issue&.author || merge_request&.author || association(:user) } end end diff --git a/spec/factories/resource_state_event.rb b/spec/factories/resource_state_event.rb index e3de462b797..926c6dd8cbc 100644 --- a/spec/factories/resource_state_event.rb +++ b/spec/factories/resource_state_event.rb @@ -2,9 +2,9 @@ FactoryBot.define do factory :resource_state_event do - issue { merge_request.nil? ? create(:issue) : nil } + issue { merge_request.nil? ? association(:issue) : nil } merge_request { nil } state { :opened } - user { issue&.author || merge_request&.author || create(:user) } + user { issue&.author || merge_request&.author || association(:user) } end end diff --git a/spec/factories/serverless/domain.rb b/spec/factories/serverless/domain.rb index 7a6a048fb34..c09af068d19 100644 --- a/spec/factories/serverless/domain.rb +++ b/spec/factories/serverless/domain.rb @@ -3,8 +3,8 @@ FactoryBot.define do factory :serverless_domain, class: '::Serverless::Domain' do function_name { 'test-function' } - serverless_domain_cluster { create(:serverless_domain_cluster) } - environment { create(:environment) } + serverless_domain_cluster { association(:serverless_domain_cluster) } + environment { association(:environment) } skip_create end diff --git a/spec/factories/serverless/domain_cluster.rb b/spec/factories/serverless/domain_cluster.rb index 40e0ecad5ad..e8ff6cf42b2 100644 --- a/spec/factories/serverless/domain_cluster.rb +++ b/spec/factories/serverless/domain_cluster.rb @@ -2,9 +2,9 @@ FactoryBot.define do factory :serverless_domain_cluster, class: '::Serverless::DomainCluster' do - pages_domain { create(:pages_domain) } - knative { create(:clusters_applications_knative) } - creator { create(:user) } + pages_domain { association(:pages_domain) } + knative { association(:clusters_applications_knative) } + creator { association(:user) } certificate do File.read(Rails.root.join('spec/fixtures/', 'ssl_certificate.pem')) diff --git a/spec/factories/services.rb b/spec/factories/services.rb index 13997080817..1935ace8e96 100644 --- a/spec/factories/services.rb +++ b/spec/factories/services.rb @@ -56,6 +56,10 @@ FactoryBot.define do trait :inactive do active { false } end + + before(:create) do |service| + service.data = build(:alerts_service_data, service: service) + end end factory :drone_ci_service do @@ -79,6 +83,8 @@ FactoryBot.define do jira_issue_transition_id { '56-1' } issues_enabled { false } project_key { nil } + vulnerabilities_enabled { false } + vulnerabilities_issuetype { nil } end before(:create) do |service, evaluator| @@ -86,7 +92,8 @@ FactoryBot.define do create(:jira_tracker_data, service: service, url: evaluator.url, api_url: evaluator.api_url, jira_issue_transition_id: evaluator.jira_issue_transition_id, username: evaluator.username, password: evaluator.password, issues_enabled: evaluator.issues_enabled, - project_key: evaluator.project_key + project_key: evaluator.project_key, vulnerabilities_enabled: evaluator.vulnerabilities_enabled, + vulnerabilities_issuetype: evaluator.vulnerabilities_issuetype ) end end @@ -139,6 +146,13 @@ FactoryBot.define do end end + factory :external_wiki_service do + project + type { ExternalWikiService } + active { true } + external_wiki_url { 'http://external-wiki-url.com' } + end + factory :open_project_service do project active { true } diff --git a/spec/factories/terraform/state.rb b/spec/factories/terraform/state.rb index d80c1315e28..c54a8aedbc6 100644 --- a/spec/factories/terraform/state.rb +++ b/spec/factories/terraform/state.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :terraform_state, class: 'Terraform::State' do - project { create(:project) } + project { association(:project) } sequence(:name) { |n| "state-#{n}" } @@ -14,12 +14,12 @@ FactoryBot.define do trait :locked do sequence(:lock_xid) { |n| "lock-#{n}" } locked_at { Time.current } - locked_by_user { create(:user) } + locked_by_user { association(:user) } end trait :with_version do after(:create) do |state| - create(:terraform_state_version, :with_file, terraform_state: state) + create(:terraform_state_version, terraform_state: state) end end diff --git a/spec/factories/terraform/state_version.rb b/spec/factories/terraform/state_version.rb index b45bd01fd3c..c6bd08815cf 100644 --- a/spec/factories/terraform/state_version.rb +++ b/spec/factories/terraform/state_version.rb @@ -4,6 +4,7 @@ FactoryBot.define do factory :terraform_state_version, class: 'Terraform::StateVersion' do terraform_state factory: :terraform_state created_by_user factory: :user + build { association(:ci_build, project: terraform_state.project) } sequence(:version) file { fixture_file_upload('spec/fixtures/terraform/terraform.tfstate', 'application/json') } diff --git a/spec/factories/uploads.rb b/spec/factories/uploads.rb index b19af277cc3..85237e2d791 100644 --- a/spec/factories/uploads.rb +++ b/spec/factories/uploads.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :upload do - model { create(:project) } + model { association(:project) } size { 100.kilobytes } uploader { "AvatarUploader" } mount_point { :avatar } @@ -20,7 +20,7 @@ FactoryBot.define do end trait :personal_snippet_upload do - model { create(:personal_snippet) } + model { association(:personal_snippet) } path { File.join(secret, filename) } uploader { "PersonalFileUploader" } secret { SecureRandom.hex } @@ -46,7 +46,7 @@ FactoryBot.define do end trait :namespace_upload do - model { create(:group) } + model { association(:group) } path { File.join(secret, filename) } uploader { "NamespaceFileUploader" } secret { SecureRandom.hex } @@ -54,7 +54,7 @@ FactoryBot.define do end trait :favicon_upload do - model { create(:appearance) } + model { association(:appearance) } uploader { "FaviconUploader" } secret { SecureRandom.hex } mount_point { :favicon } @@ -62,13 +62,13 @@ FactoryBot.define do trait :attachment_upload do mount_point { :attachment } - model { create(:note) } + model { association(:note) } uploader { "AttachmentUploader" } end trait :design_action_image_v432x230_upload do mount_point { :image_v432x230 } - model { create(:design_action) } + model { association(:design_action) } uploader { ::DesignManagement::DesignV432x230Uploader.name } end end diff --git a/spec/factories/usage_data.rb b/spec/factories/usage_data.rb index adca6eabb0e..87f806a3d74 100644 --- a/spec/factories/usage_data.rb +++ b/spec/factories/usage_data.rb @@ -52,6 +52,11 @@ FactoryBot.define do create(:protected_branch, project: projects[0]) create(:protected_branch, name: 'main', project: projects[0]) + # Alert Management + create(:alert_management_http_integration, project: projects[0], name: 'DataDog') + create(:alert_management_http_integration, project: projects[0], name: 'DataCat') + create(:alert_management_http_integration, :inactive, project: projects[1], name: 'DataFox') + # Tracing create(:project_tracing_setting, project: projects[0]) diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 2e5b3be3bf2..1b430009ab5 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -66,7 +66,7 @@ FactoryBot.define do trait :with_sign_ins do sign_in_count { 3 } - current_sign_in_at { Time.now } + current_sign_in_at { FFaker::Time.between(10.days.ago, 1.day.ago) } last_sign_in_at { FFaker::Time.between(10.days.ago, 1.day.ago) } current_sign_in_ip { '127.0.0.1' } last_sign_in_ip { '127.0.0.1' } diff --git a/spec/factories/wiki_pages.rb b/spec/factories/wiki_pages.rb index 3397277839e..6f912a183e8 100644 --- a/spec/factories/wiki_pages.rb +++ b/spec/factories/wiki_pages.rb @@ -39,14 +39,14 @@ FactoryBot.define do factory :wiki_page_meta, class: 'WikiPage::Meta' do title { generate(:wiki_page_title) } - project { create(:project) } + project { association(:project) } trait :for_wiki_page do transient do - wiki_page { create(:wiki_page, container: project) } + wiki_page { association(:wiki_page, container: project) } end - project { @overrides[:wiki_page]&.container || create(:project) } + project { @overrides[:wiki_page]&.container || association(:project) } title { wiki_page.title } initialize_with do @@ -58,7 +58,7 @@ FactoryBot.define do end factory :wiki_page_slug, class: 'WikiPage::Slug' do - wiki_page_meta { create(:wiki_page_meta) } + wiki_page_meta { association(:wiki_page_meta) } slug { generate(:sluggified_title) } canonical { false } diff --git a/spec/factories/wikis.rb b/spec/factories/wikis.rb index 86d98bfd756..05f6fb0de58 100644 --- a/spec/factories/wikis.rb +++ b/spec/factories/wikis.rb @@ -17,5 +17,9 @@ FactoryBot.define do container { project } end + + trait :empty_repo do + after(:create, &:create_wiki_repository) + end end end |