diff options
Diffstat (limited to 'spec/factories')
23 files changed, 127 insertions, 37 deletions
diff --git a/spec/factories/alert_management/alerts.rb b/spec/factories/alert_management/alerts.rb index 7e9e58edc1e..443e43d5fd1 100644 --- a/spec/factories/alert_management/alerts.rb +++ b/spec/factories/alert_management/alerts.rb @@ -95,10 +95,6 @@ FactoryBot.define do severity { 'unknown' } end - trait :threat_monitoring do - domain { :threat_monitoring } - end - trait :prometheus do monitoring_tool { Gitlab::AlertManagement::Payload::MONITORING_TOOLS[:prometheus] } payload do diff --git a/spec/factories/application_settings.rb b/spec/factories/application_settings.rb index c28d3c20a86..844e21df60c 100644 --- a/spec/factories/application_settings.rb +++ b/spec/factories/application_settings.rb @@ -5,5 +5,9 @@ FactoryBot.define do default_projects_limit { 42 } import_sources { [] } restricted_visibility_levels { [] } + + after(:build) do |settings| + settings.ensure_key_restrictions! + end end end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 56c12d73a3b..97ddbf21b99 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -33,6 +33,18 @@ FactoryBot.define do name { generate(:job_name) } end + trait :matrix do + sequence(:name) { |n| "job: [#{n}]" } + options do + { + parallel: { + total: 2, + matrix: [{ ID: %w[1 2] }] + } + } + end + end + trait :dependent do scheduling_type { 'dag' } @@ -494,13 +506,15 @@ FactoryBot.define do trait :with_commit do after(:build) do |build| - allow(build).to receive(:commit).and_return build(:commit, :without_author) + commit = build(:commit, :without_author) + stub_method(build, :commit) { commit } end end trait :with_commit_and_author do after(:build) do |build| - allow(build).to receive(:commit).and_return build(:commit) + commit = build(:commit) + stub_method(build, :commit) { commit } end end diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb index 10fa739acc1..919b45e57e2 100644 --- a/spec/factories/clusters/applications/helm.rb +++ b/spec/factories/clusters/applications/helm.rb @@ -10,19 +10,18 @@ FactoryBot.define do before(:create) do |_record, evaluator| if evaluator.helm_installed - 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')), - cert_string: File.read(Rails.root.join('spec/fixtures/clusters/sample_cert.pem')) - ) + stub_method(Gitlab::Kubernetes::Helm::V2::Certificate, :generate_root) do + OpenStruct.new( # rubocop: disable Style/OpenStructUse + key_string: File.read(Rails.root.join('spec/fixtures/clusters/sample_key.key')), + cert_string: File.read(Rails.root.join('spec/fixtures/clusters/sample_cert.pem')) ) + end end end after(:create) do |_record, evaluator| if evaluator.helm_installed - allow(Gitlab::Kubernetes::Helm::V2::Certificate).to receive(:generate_root).and_call_original + restore_original_methods(Gitlab::Kubernetes::Helm::V2::Certificate) end end diff --git a/spec/factories/clusters/cluster_enabled_grant.rb b/spec/factories/clusters/cluster_enabled_grant.rb new file mode 100644 index 00000000000..f995bc876f3 --- /dev/null +++ b/spec/factories/clusters/cluster_enabled_grant.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :cluster_enabled_grant, class: 'Clusters::ClusterEnabledGrant' do + namespace + end +end diff --git a/spec/factories/commit_signature/ssh_signature.rb b/spec/factories/commit_signature/ssh_signature.rb new file mode 100644 index 00000000000..097415ba69c --- /dev/null +++ b/spec/factories/commit_signature/ssh_signature.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ssh_signature, class: 'CommitSignatures::SshSignature' do + commit_sha { Digest::SHA1.hexdigest(SecureRandom.hex) } + project + key + verification_status { :verified } + end +end diff --git a/spec/factories/commits.rb b/spec/factories/commits.rb index d006f9baf1f..4b1c74110ef 100644 --- a/spec/factories/commits.rb +++ b/spec/factories/commits.rb @@ -28,19 +28,20 @@ FactoryBot.define do end after(:build) do |commit, evaluator| - allow(commit).to receive(:author).and_return(evaluator.author || build_stubbed(:author)) - allow(commit).to receive(:parent_ids).and_return([]) + author = evaluator.author || build_stubbed(:author) + stub_method(commit, :author) { author } + stub_method(commit, :parent_ids) { [] } end trait :merge_commit do after(:build) do |commit| - allow(commit).to receive(:parent_ids).and_return(Array.new(2) { SecureRandom.hex(20) }) + stub_method(commit, :parent_ids) { Array.new(2) { SecureRandom.hex(20) } } end end trait :without_author do after(:build) do |commit| - allow(commit).to receive(:author).and_return nil + stub_method(commit, :author) { nil } end end end diff --git a/spec/factories/container_repositories.rb b/spec/factories/container_repositories.rb index ce83e9e8006..210441430b0 100644 --- a/spec/factories/container_repositories.rb +++ b/spec/factories/container_repositories.rb @@ -85,13 +85,12 @@ FactoryBot.define do tags = evaluator.tags # convert Array into Hash tags = tags.product(['sha256:4c8e63ca4cb663ce6c688cb06f1c372b088dac5b6d7ad7d49cd620d85cf72a15']).to_h unless tags.is_a?(Hash) - - allow(repository.client) - .to receive(:repository_tags) - .and_return({ + stub_method(repository.client, :repository_tags) do |*args| + { 'name' => repository.path, 'tags' => tags.keys - }) + } + end tags.each_pair do |tag, digest| allow(repository.client) diff --git a/spec/factories/deployments.rb b/spec/factories/deployments.rb index ab1b794632a..204b917fa4a 100644 --- a/spec/factories/deployments.rb +++ b/spec/factories/deployments.rb @@ -15,7 +15,7 @@ FactoryBot.define do deployment.user ||= deployment.project.creator unless deployment.project.repository_exists? - allow(deployment.project.repository).to receive(:create_ref) + stub_method(deployment.project.repository, :create_ref) { nil } end if deployment.cluster && deployment.cluster.project_type? && deployment.cluster.project.nil? diff --git a/spec/factories/environments.rb b/spec/factories/environments.rb index 0a9255e1abe..ccd2011eb8d 100644 --- a/spec/factories/environments.rb +++ b/spec/factories/environments.rb @@ -46,7 +46,7 @@ FactoryBot.define do after(:create) do |environment, evaluator| pipeline = create(:ci_pipeline, project: environment.project) - deployable = create(:ci_build, name: "#{environment.name}:deploy", + deployable = create(:ci_build, :success, name: "#{environment.name}:deploy", pipeline: pipeline) deployment = create(:deployment, diff --git a/spec/factories/gitlab/database/background_migration/batched_migrations.rb b/spec/factories/gitlab/database/background_migration/batched_migrations.rb index 5ff90ff44b9..ea0fb571cc4 100644 --- a/spec/factories/gitlab/database/background_migration/batched_migrations.rb +++ b/spec/factories/gitlab/database/background_migration/batched_migrations.rb @@ -12,6 +12,7 @@ FactoryBot.define do sequence(:job_arguments) { |n| [["column_#{n}"], ["column_#{n}_convert_to_bigint"]] } total_tuple_count { 10_000 } pause_ms { 100 } + gitlab_schema { :gitlab_main } trait(:paused) do status { 0 } diff --git a/spec/factories/incident_management/timeline_events.rb b/spec/factories/incident_management/timeline_events.rb index e2e216d24b8..831f78369b7 100644 --- a/spec/factories/incident_management/timeline_events.rb +++ b/spec/factories/incident_management/timeline_events.rb @@ -10,5 +10,14 @@ FactoryBot.define do note { 'timeline created' } note_html { '<strong>timeline created</strong>' } action { 'comment' } + editable + end + + trait :editable do + editable { true } + end + + trait :non_editable do + editable { false } end end diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index 8c714f7736f..88522737e06 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -41,6 +41,13 @@ FactoryBot.define do end end + trait :closed_as_duplicate do + closed + after(:create) do |issue| + issue.update!(duplicated_to: create(:issue, project: issue.project)) + end + end + after(:build) do |issue, evaluator| issue.state_id = Issue.available_states[evaluator.state] end diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index e897a5e022a..4941a31982f 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -25,10 +25,6 @@ FactoryBot.define do title { generate(:draft_title) } end - trait :wip_merge_request do - title { generate(:wip_title) } - end - trait :jira_title do title { generate(:jira_title) } end @@ -324,7 +320,7 @@ FactoryBot.define do # Fake `fetch_ref!` if we don't have repository # We have too many existing tests relying on this behaviour unless [target_project, source_project].all?(&:repository_exists?) - allow(merge_request).to receive(:fetch_ref!) + stub_method(merge_request, :fetch_ref!) { nil } end end diff --git a/spec/factories/plan_limits.rb b/spec/factories/plan_limits.rb index ad10629af05..1e4f70cd925 100644 --- a/spec/factories/plan_limits.rb +++ b/spec/factories/plan_limits.rb @@ -6,8 +6,10 @@ FactoryBot.define do dast_profile_schedules { 50 } - trait :default_plan do - plan factory: :default_plan + Plan.all_plans.each do |plan| + trait :"#{plan}_plan" do + plan factory: :"#{plan}_plan" + end end trait :with_package_file_sizes do diff --git a/spec/factories/project_members.rb b/spec/factories/project_members.rb index c38257b06b6..ab1e45acc15 100644 --- a/spec/factories/project_members.rb +++ b/spec/factories/project_members.rb @@ -6,10 +6,11 @@ FactoryBot.define do source { association(:project) } maintainer - trait(:guest) { access_level { ProjectMember::GUEST } } - trait(:reporter) { access_level { ProjectMember::REPORTER } } + trait(:guest) { access_level { ProjectMember::GUEST } } + trait(:reporter) { access_level { ProjectMember::REPORTER } } trait(:developer) { access_level { ProjectMember::DEVELOPER } } trait(:maintainer) { access_level { ProjectMember::MAINTAINER } } + trait(:owner) { access_level { ProjectMember::OWNER } } trait(:access_request) { requested_at { Time.now } } trait(:invited) do diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index c3c02782578..86321350962 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -29,6 +29,7 @@ FactoryBot.define do merge_requests_access_level { ProjectFeature::ENABLED } repository_access_level { ProjectFeature::ENABLED } analytics_access_level { ProjectFeature::ENABLED } + package_registry_access_level { ProjectFeature::ENABLED } pages_access_level do visibility_level == Gitlab::VisibilityLevel::PUBLIC ? ProjectFeature::ENABLED : ProjectFeature::PRIVATE end @@ -67,6 +68,7 @@ FactoryBot.define do forking_access_level: evaluator.forking_access_level, merge_requests_access_level: merge_requests_access_level, repository_access_level: evaluator.repository_access_level, + package_registry_access_level: evaluator.package_registry_access_level, pages_access_level: evaluator.pages_access_level, metrics_dashboard_access_level: evaluator.metrics_dashboard_access_level, operations_access_level: evaluator.operations_access_level, @@ -301,8 +303,8 @@ FactoryBot.define do 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) + stub_method(project, :empty_repo?) { false } + stub_method(project.repository, :empty?) { false } end end diff --git a/spec/factories/releases.rb b/spec/factories/releases.rb index 52a9341b955..a07d4ef6c2e 100644 --- a/spec/factories/releases.rb +++ b/spec/factories/releases.rb @@ -14,7 +14,11 @@ FactoryBot.define do trait :legacy do sha { nil } - author { nil } + + # Legacy releases which are created during tags creation have empty users. + after(:create) do |release, _| + release.update_column(:author_id, nil) + end end trait :with_evidence do diff --git a/spec/factories/sequences.rb b/spec/factories/sequences.rb index 6b86154aa91..c10fab8588d 100644 --- a/spec/factories/sequences.rb +++ b/spec/factories/sequences.rb @@ -16,7 +16,6 @@ FactoryBot.define do sequence(:oid) { |n| Digest::SHA2.hexdigest("oid-like-#{n}") } sequence(:variable) { |n| "var#{n}" } sequence(:draft_title) { |n| "Draft: #{n}" } - sequence(:wip_title) { |n| "WIP: #{n}" } sequence(:jira_title) { |n| "[PROJ-#{n}]: fix bug" } sequence(:jira_description) { |n| "This is a description\n here is the description\n Related to: PROJ-#{n}" } sequence(:jira_branch) { |n| "feature/PROJ-#{n}" } diff --git a/spec/factories/terraform/state.rb b/spec/factories/terraform/state.rb index fb63c845073..c40fa14b4f8 100644 --- a/spec/factories/terraform/state.rb +++ b/spec/factories/terraform/state.rb @@ -12,6 +12,10 @@ FactoryBot.define do locked_by_user { association(:user) } end + trait :deletion_in_progress do + deleted_at { Time.current } + end + trait :with_version do after(:create) do |state| create(:terraform_state_version, terraform_state: state) diff --git a/spec/factories/time_tracking/timelog_categories.rb b/spec/factories/time_tracking/timelog_categories.rb new file mode 100644 index 00000000000..80fd9b7901a --- /dev/null +++ b/spec/factories/time_tracking/timelog_categories.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :timelog_category, class: 'TimeTracking::TimelogCategory' do + namespace + + name { generate(:name) } + end +end diff --git a/spec/factories/work_items.rb b/spec/factories/work_items.rb index 6d9dcac6165..e80aa9cc008 100644 --- a/spec/factories/work_items.rb +++ b/spec/factories/work_items.rb @@ -9,5 +9,10 @@ FactoryBot.define do relative_position { RelativePositioning::START_POSITION } issue_type { :issue } association :work_item_type, :default + + trait :task do + issue_type { :task } + association :work_item_type, :default, :task + end end end diff --git a/spec/factories/work_items/parent_links.rb b/spec/factories/work_items/parent_links.rb new file mode 100644 index 00000000000..886aa449a57 --- /dev/null +++ b/spec/factories/work_items/parent_links.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :parent_link, class: 'WorkItems::ParentLink' do + transient do + work_item { nil } + work_item_parent { nil } + end + + after(:build) do |link, evaluator| + link.work_item = evaluator.work_item + link.work_item_parent = evaluator.work_item_parent + + unless link.work_item && link.work_item_parent + project = link.work_item&.project || link.work_item_parent&.project || create(:project) + link.work_item ||= create(:work_item, :task, project: project) + link.work_item_parent ||= create(:work_item, project: project) + end + end + end +end |