diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/factories | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) | |
download | gitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/factories')
31 files changed, 243 insertions, 26 deletions
diff --git a/spec/factories/alert_management/alerts.rb b/spec/factories/alert_management/alerts.rb index 881f633829a..d931947fff1 100644 --- a/spec/factories/alert_management/alerts.rb +++ b/spec/factories/alert_management/alerts.rb @@ -23,7 +23,7 @@ FactoryBot.define do trait :with_assignee do |alert| after(:create) do |alert| - alert.alert_assignees.create(assignee: create(:user)) + alert.alert_assignees.create!(assignee: create(:user)) end end diff --git a/spec/factories/audit_events.rb b/spec/factories/audit_events.rb new file mode 100644 index 00000000000..38414400282 --- /dev/null +++ b/spec/factories/audit_events.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :audit_event, class: 'SecurityEvent', aliases: [:user_audit_event] do + user + + transient { target_user { create(:user) } } + + entity_type { 'User' } + entity_id { target_user.id } + entity_path { target_user.full_path } + target_details { target_user.name } + ip_address { IPAddr.new '127.0.0.1' } + author_name { 'Jane Doe' } + details do + { + change: 'email address', + from: 'admin@gitlab.com', + to: 'maintainer@gitlab.com', + author_name: user.name, + target_id: target_user.id, + target_type: 'User', + target_details: target_user.name, + ip_address: '127.0.0.1', + entity_path: target_user.full_path + } + end + + trait :project_event do + transient { target_project { create(:project) } } + + entity_type { 'Project' } + entity_id { target_project.id } + entity_path { target_project.full_path } + target_details { target_project.name } + ip_address { IPAddr.new '127.0.0.1' } + details do + { + change: 'packges_enabled', + from: true, + to: false, + author_name: user.name, + target_id: target_project.id, + target_type: 'Project', + target_details: target_project.name, + ip_address: '127.0.0.1', + entity_path: target_project.full_path + } + end + end + + trait :group_event do + transient { target_group { create(:group) } } + + entity_type { 'Group' } + entity_id { target_group.id } + entity_path { target_group.full_path } + target_details { target_group.name } + ip_address { IPAddr.new '127.0.0.1' } + details do + { + change: 'project_creation_level', + from: nil, + to: 'Developers + Maintainers', + author_name: user.name, + target_id: target_group.id, + target_type: 'Group', + target_details: target_group.name, + ip_address: '127.0.0.1', + entity_path: target_group.full_path + } + end + end + + factory :project_audit_event, traits: [:project_event] + factory :group_audit_event, traits: [:group_event] + end +end diff --git a/spec/factories/boards.rb b/spec/factories/boards.rb index a201ca94380..cef7ec37f07 100644 --- a/spec/factories/boards.rb +++ b/spec/factories/boards.rb @@ -28,7 +28,7 @@ FactoryBot.define do end after(:create) do |board| - board.lists.create(list_type: :closed) + board.lists.create!(list_type: :closed) end end end diff --git a/spec/factories/ci/pipeline_artifacts.rb b/spec/factories/ci/pipeline_artifacts.rb new file mode 100644 index 00000000000..ecfd1e79e78 --- /dev/null +++ b/spec/factories/ci/pipeline_artifacts.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ci_pipeline_artifact, class: 'Ci::PipelineArtifact' do + pipeline factory: :ci_pipeline + project { pipeline.project } + file_type { :code_coverage } + file_format { :raw } + file_store { Ci::PipelineArtifact::FILE_STORE_SUPPORTED.first } + size { 1.megabytes } + + after(:build) do |artifact, _evaluator| + artifact.file = fixture_file_upload( + Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage.json'), 'application/json') + end + end +end diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb index 5bd5ab7d67a..2790be8b70d 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -17,7 +17,7 @@ FactoryBot.define do after(:create) do |pipeline, evaluator| merge_request = evaluator.head_pipeline_of - merge_request&.update(head_pipeline: pipeline) + merge_request&.update!(head_pipeline: pipeline) end factory :ci_pipeline do diff --git a/spec/factories/clusters/agent_tokens.rb b/spec/factories/clusters/agent_tokens.rb new file mode 100644 index 00000000000..6f92f2217b3 --- /dev/null +++ b/spec/factories/clusters/agent_tokens.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :cluster_agent_token, class: 'Clusters::AgentToken' do + association :agent, factory: :cluster_agent + + token_encrypted { Gitlab::CryptoHelper.aes256_gcm_encrypt(SecureRandom.hex(50)) } + end +end diff --git a/spec/factories/clusters/agents.rb b/spec/factories/clusters/agents.rb new file mode 100644 index 00000000000..334671f69f0 --- /dev/null +++ b/spec/factories/clusters/agents.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :cluster_agent, class: 'Clusters::Agent' do + project + + sequence(:name) { |n| "agent-#{n}" } + end +end diff --git a/spec/factories/design_management/designs.rb b/spec/factories/design_management/designs.rb index 6d1229063d8..66c33c9ece0 100644 --- a/spec/factories/design_management/designs.rb +++ b/spec/factories/design_management/designs.rb @@ -22,8 +22,12 @@ FactoryBot.define do imported { true } end + trait :with_relative_position do + sequence(:relative_position) { |n| n * 1000 } + end + create_versions = ->(design, evaluator, commit_version) do - unless evaluator.versions_count.zero? + unless evaluator.versions_count == 0 project = design.project issue = design.issue repository = project.design_repository @@ -34,7 +38,7 @@ FactoryBot.define do 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 + version.save!(validate: false) # We need it to have an ID, validate later Gitlab::Database.bulk_insert(dv_table_name, [action.row_attrs(version)]) # rubocop:disable Gitlab/BulkInsert end diff --git a/spec/factories/design_management/versions.rb b/spec/factories/design_management/versions.rb index e6d17ba691c..a5c0e7076e9 100644 --- a/spec/factories/design_management/versions.rb +++ b/spec/factories/design_management/versions.rb @@ -40,7 +40,7 @@ FactoryBot.define do ) version.designs += specific_designs - unless evaluator.designs_count.zero? || version.designs.present? + unless evaluator.designs_count == 0 || version.designs.present? version.designs << create(:design, issue: version.issue) end end @@ -135,7 +135,7 @@ FactoryBot.define do actions: version_actions ) - version.update(sha: sha) + version.update!(sha: sha) end end end diff --git a/spec/factories/emails.rb b/spec/factories/emails.rb index 284ba631c37..b30fa8a5896 100644 --- a/spec/factories/emails.rb +++ b/spec/factories/emails.rb @@ -6,6 +6,6 @@ FactoryBot.define do email { generate(:email_alias) } trait(:confirmed) { confirmed_at { Time.now } } - trait(:skip_validate) { to_create {|instance| instance.save(validate: false) } } + trait(:skip_validate) { to_create {|instance| instance.save!(validate: false) } } end end diff --git a/spec/factories/experiments.rb b/spec/factories/experiments.rb new file mode 100644 index 00000000000..2c51a6585f4 --- /dev/null +++ b/spec/factories/experiments.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :experiment do + name { generate(:title) } + end +end diff --git a/spec/factories/group_deploy_keys_groups.rb b/spec/factories/group_deploy_keys_groups.rb new file mode 100644 index 00000000000..14a4ca77392 --- /dev/null +++ b/spec/factories/group_deploy_keys_groups.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :group_deploy_keys_group do + group_deploy_key + group + can_push { true } + end +end diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index 4d0924a9412..99fe2ef9c0a 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -7,6 +7,7 @@ FactoryBot.define do author { project.creator } updated_by { author } relative_position { RelativePositioning::START_POSITION } + issue_type { :issue } trait :confidential do confidential { true } @@ -38,8 +39,12 @@ FactoryBot.define do end after(:create) do |issue, evaluator| - issue.update(labels: evaluator.labels) + issue.update!(labels: evaluator.labels) end end + + factory :incident do + issue_type { :incident } + end end end diff --git a/spec/factories/iterations.rb b/spec/factories/iterations.rb index f6be1d9d752..bd61cd469af 100644 --- a/spec/factories/iterations.rb +++ b/spec/factories/iterations.rb @@ -36,6 +36,12 @@ FactoryBot.define do end end + trait(:skip_project_validation) do + after(:stub, :build) do |iteration| + iteration.skip_project_validation = true + end + end + after(:build, :stub) do |iteration, evaluator| if evaluator.group iteration.group = evaluator.group @@ -49,7 +55,7 @@ FactoryBot.define do id = evaluator.resource_parent.id evaluator.resource_parent.is_a?(Group) ? evaluator.group_id = id : evaluator.project_id = id else - iteration.project = create(:project) + iteration.group = create(:group) end end diff --git a/spec/factories/labels.rb b/spec/factories/labels.rb index 2e783adcc94..6725b571f19 100644 --- a/spec/factories/labels.rb +++ b/spec/factories/labels.rb @@ -27,7 +27,7 @@ FactoryBot.define do after(:create) do |label, evaluator| if evaluator.priority - label.priorities.create(project: label.project, priority: evaluator.priority) + label.priorities.create!(project: label.project, priority: evaluator.priority) end end end diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index 2a06690f894..af6e88f73b1 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -43,6 +43,21 @@ FactoryBot.define do state_id { MergeRequest.available_states[:merged] } end + trait :with_merged_metrics do + merged + + transient do + merged_by { author } + end + + after(:build) do |merge_request, evaluator| + metrics = merge_request.build_metrics + metrics.merged_at = 1.week.ago + metrics.merged_by = evaluator.merged_by + metrics.pipeline = create(:ci_empty_pipeline) + end + end + trait :merged_target do source_branch { "merged-target" } target_branch { "improve/awesome" } @@ -268,7 +283,7 @@ FactoryBot.define do end after(:create) do |merge_request, evaluator| - merge_request.update(labels: evaluator.labels) + merge_request.update!(labels: evaluator.labels) end end end diff --git a/spec/factories/namespace_settings.rb b/spec/factories/namespace_settings.rb new file mode 100644 index 00000000000..388ea7dab91 --- /dev/null +++ b/spec/factories/namespace_settings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :namespace_settings, class: 'NamespaceSetting' do + namespace + end +end diff --git a/spec/factories/namespaces.rb b/spec/factories/namespaces.rb index f4d5848e878..0dcec086da9 100644 --- a/spec/factories/namespaces.rb +++ b/spec/factories/namespaces.rb @@ -30,6 +30,10 @@ FactoryBot.define do association :root_storage_statistics, factory: :namespace_root_storage_statistics end + trait :with_namespace_settings do + association :namespace_settings, factory: :namespace_settings + end + # Construct a hierarchy underneath the namespace. # Each namespace will have `children` amount of children, # and `depth` levels of descendants. diff --git a/spec/factories/packages.rb b/spec/factories/packages.rb index 562269a67bc..a7902f6f105 100644 --- a/spec/factories/packages.rb +++ b/spec/factories/packages.rb @@ -10,7 +10,7 @@ FactoryBot.define do maven_metadatum after :build do |package| - package.maven_metadatum.path = "#{package.name}/#{package.version}" + package.maven_metadatum.path = package.version? ? "#{package.name}/#{package.version}" : package.name end after :create do |package| diff --git a/spec/factories/plans.rb b/spec/factories/plans.rb index 81506edcf16..903c176ec2a 100644 --- a/spec/factories/plans.rb +++ b/spec/factories/plans.rb @@ -6,7 +6,7 @@ FactoryBot.define do factory :"#{plan}_plan" do name { plan } title { name.titleize } - initialize_with { Plan.find_or_create_by(name: plan) } + initialize_with { Plan.find_or_create_by!(name: plan) } end end end diff --git a/spec/factories/project_hooks.rb b/spec/factories/project_hooks.rb index 6592141e26d..15b240acba4 100644 --- a/spec/factories/project_hooks.rb +++ b/spec/factories/project_hooks.rb @@ -21,6 +21,7 @@ FactoryBot.define do job_events { true } pipeline_events { true } wiki_page_events { true } + deployment_events { true } end end end diff --git a/spec/factories/project_repository_storage_moves.rb b/spec/factories/project_repository_storage_moves.rb index ea0b34e0338..69fb3af45e6 100644 --- a/spec/factories/project_repository_storage_moves.rb +++ b/spec/factories/project_repository_storage_moves.rb @@ -15,6 +15,10 @@ FactoryBot.define do state { ProjectRepositoryStorageMove.state_machines[:state].states[:started].value } end + trait :replicated do + state { ProjectRepositoryStorageMove.state_machines[:state].states[:replicated].value } + end + trait :finished do state { ProjectRepositoryStorageMove.state_machines[:state].states[:finished].value } end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index e4b53186ea8..328b7f9a229 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -61,7 +61,7 @@ FactoryBot.define do hash.store("pages_access_level", evaluator.pages_access_level) end - project.project_feature.update(hash) + project.project_feature.update!(hash) # Normally the class Projects::CreateService is used for creating # projects, and this class takes care of making sure the owner and current @@ -82,7 +82,7 @@ FactoryBot.define do import_state.jid = evaluator.import_jid import_state.correlation_id_value = evaluator.import_correlation_id import_state.last_error = evaluator.import_last_error - import_state.save + import_state.save! end end @@ -389,4 +389,8 @@ FactoryBot.define do create(:design, project: project, issue: issue) end end + + trait :in_subgroup do + namespace factory: [:group, :nested] + end end diff --git a/spec/factories/prometheus_alert.rb b/spec/factories/prometheus_alert.rb index a9fede9efca..18cf1a20e0d 100644 --- a/spec/factories/prometheus_alert.rb +++ b/spec/factories/prometheus_alert.rb @@ -13,5 +13,9 @@ FactoryBot.define do prometheus_metric do |alert| build(:prometheus_metric, project: alert.project) end + + trait :with_runbook_url do + runbook_url { 'https://runbooks.gitlab.com/metric_gt_1'} + end end end diff --git a/spec/factories/protected_branches/merge_access_levels.rb b/spec/factories/protected_branches/merge_access_levels.rb new file mode 100644 index 00000000000..779a8617de1 --- /dev/null +++ b/spec/factories/protected_branches/merge_access_levels.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :protected_branch_merge_access_level, class: 'ProtectedBranch::MergeAccessLevel' do + protected_branch + access_level { Gitlab::Access::DEVELOPER } + end +end diff --git a/spec/factories/protected_branches/push_access_levels.rb b/spec/factories/protected_branches/push_access_levels.rb new file mode 100644 index 00000000000..fa3a35fe282 --- /dev/null +++ b/spec/factories/protected_branches/push_access_levels.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :protected_branch_push_access_level, class: 'ProtectedBranch::PushAccessLevel' do + protected_branch + access_level { Gitlab::Access::DEVELOPER } + end +end diff --git a/spec/factories/raw_usage_data.rb b/spec/factories/raw_usage_data.rb new file mode 100644 index 00000000000..e0ef357fdbd --- /dev/null +++ b/spec/factories/raw_usage_data.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :raw_usage_data do + recorded_at { Time.current } + payload { { test: 'test' } } + end +end diff --git a/spec/factories/resource_iteration_event.rb b/spec/factories/resource_iteration_event.rb new file mode 100644 index 00000000000..85e7320f7a7 --- /dev/null +++ b/spec/factories/resource_iteration_event.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :resource_iteration_event do + issue { merge_request.nil? ? create(:issue) : nil } + merge_request { nil } + iteration + action { :add } + user { issue&.author || merge_request&.author || create(:user) } + end +end diff --git a/spec/factories/services.rb b/spec/factories/services.rb index 9a521336fee..7fbf6f16dc7 100644 --- a/spec/factories/services.rb +++ b/spec/factories/services.rb @@ -116,12 +116,6 @@ FactoryBot.define do issue_tracker end - factory :gitlab_issue_tracker_service do - project - active { true } - issue_tracker - end - trait :issue_tracker do transient do create_data { true } @@ -196,7 +190,7 @@ FactoryBot.define do IssueTrackerService.skip_callback(:validation, :before, :handle_properties) end - to_create { |instance| instance.save(validate: false) } + to_create { |instance| instance.save!(validate: false) } after(:create) do IssueTrackerService.set_callback(:validation, :before, :handle_properties) diff --git a/spec/factories/usage_data.rb b/spec/factories/usage_data.rb index 518b5b5e76a..d2b8fd94aca 100644 --- a/spec/factories/usage_data.rb +++ b/spec/factories/usage_data.rb @@ -24,13 +24,15 @@ FactoryBot.define do create(:service, project: projects[2], type: 'SlackService', active: true) create(:service, project: projects[2], type: 'MattermostService', active: false) create(:service, :template, type: 'MattermostService', active: true) + matermost_instance = create(:service, :instance, type: 'MattermostService', active: true) + create(:service, project: projects[1], type: 'MattermostService', active: true, inherit_from_id: matermost_instance.id) create(:service, project: projects[2], type: 'CustomIssueTrackerService', active: true) create(:project_error_tracking_setting, project: projects[0]) create(:project_error_tracking_setting, project: projects[1], enabled: false) create(:alerts_service, project: projects[0]) create(:alerts_service, :inactive, project: projects[1]) - 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) + alert_bot_issues = create_list(:incident, 2, project: projects[0], author: User.alert_bot) + create_list(:incident, 2, project: projects[1], author: User.alert_bot) issues = create_list(:issue, 4, project: projects[0]) create_list(:prometheus_alert, 2, project: projects[0]) create(:prometheus_alert, project: projects[1]) @@ -45,6 +47,8 @@ FactoryBot.define do create(:zoom_meeting, project: projects[0], issue: projects[0].issues[2], issue_status: :added) create_list(:zoom_meeting, 2, project: projects[0], issue: projects[0].issues[2], issue_status: :removed) create(:sentry_issue, issue: projects[0].issues[0]) + create(:protected_branch, project: projects[0]) + create(:protected_branch, name: 'main', project: projects[0]) # Incident Labeled Issues incident_label_attrs = IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES diff --git a/spec/factories/wiki_pages.rb b/spec/factories/wiki_pages.rb index e7fcc19bbfe..cc866d336a4 100644 --- a/spec/factories/wiki_pages.rb +++ b/spec/factories/wiki_pages.rb @@ -31,7 +31,8 @@ FactoryBot.define do end to_create do |page, evaluator| - page.create(message: evaluator.message) + # WikiPages is ActiveModel which doesn't support `create!`. + page.create(message: evaluator.message) # rubocop:disable Rails/SaveBang end end |