Introduce cop FactoryBot/InlineAssociation
Description of the proposal
This MR adds a new FactoryBot/InlineAssociation
to encourage the use of inline associations in FactoryBot
discouraging explicit use of create
and build
.
See #262624 for details.
The current offenses will be fixed in #267606 (closed).
Contributes to https://gitlab.com/gitlab-org/plan/-/issues/145
Context:
The surrounding code block of the examples below.
Factory.define do
factory :project, class: 'Project'
# EXAMPLE below
end
end
Bad
creator { create(:user) }
creator { FactoryBot.create(:user) }
creator { ::FactoryBot.create(:user) }
creator { create(:user, :admin) }
creator { build(:user) }
add_attribute(:creator) { build(:user) }
Good
creator { association(:user) }
creator { association(:user, :admin) }
add_attribute(:creator) { association(:user) }
Accepted but not ideal
Those instances we cannot autocorrect and is out of scope of this
after(:build) do |instance|
instance.creator = create(:user)
end
initialize_with do
create(:project)
end
pipelines { create_list(:ci_pipeline, 2) }
creator_id { create(:user).id }
Offenses
Example
spec/factories/atlassian_identities.rb:6:12: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
user { create(:user) }
^^^^^^^^^^^^^
spec/factories/gitaly/commit.rb:17:14: C: FactoryBot/InlineAssociation: Prefer inline association over build. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
author { build(:gitaly_commit_author) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
386 files inspected, 86 offenses detected
The exhausive list of fixed offenses
Inspecting 386 files
.......CC............................................................CCC..........C......CC..CCC.......C....C...........................C.........C...........CC...........................C............CCC..C..CC...............C.....C...............C..............................C........................C.................C.........C........................CC...................C........
Offenses:
spec/factories/atlassian_identities.rb:6:12: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
user { create(:user) }
^^^^^^^^^^^^^
spec/factories/audit_events.rb:7:31: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
transient { target_user { create(:user) } }
^^^^^^^^^^^^^
spec/factories/audit_events.rb:30:36: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
transient { target_project { create(:project) } }
^^^^^^^^^^^^^^^^
spec/factories/audit_events.rb:53:34: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
transient { target_group { create(:group) } }
^^^^^^^^^^^^^^
spec/factories/design_management/design_at_version.rb:12:50: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
issue { design&.issue || version&.issue || create(:issue) }
^^^^^^^^^^^^^^
spec/factories/design_management/designs.rb:5:13: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
issue { create(:issue) }
^^^^^^^^^^^^^^
spec/factories/design_management/designs.rb:6:33: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
project { issue&.project || create(:project) }
^^^^^^^^^^^^^^^^
spec/factories/design_management/versions.rb:6:37: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
issue { designs.first&.issue || create(:issue) }
^^^^^^^^^^^^^^
spec/factories/design_management/versions.rb:7:31: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
author { issue&.author || create(:user) }
^^^^^^^^^^^^^
spec/factories/events.rb:30:54: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
project { @overrides[:wiki_page]&.container || create(:project, :wiki_repo) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/events.rb:31:16: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
target { create(:wiki_page_meta, :for_wiki_page, wiki_page: wiki_page) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/events.rb:34:21: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
wiki_page { create(:wiki_page, container: project) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/events.rb:40:18: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
design { create(:design, issue: create(:issue, project: project)) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/events.rb:40:41: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
design { create(:design, issue: create(:issue, project: project)) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/events.rb:48:16: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
note { create(:note, author: author, project: project, noteable: design) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/git_wiki_commit_details.rb:8:16: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
author { create(:user) }
^^^^^^^^^^^^^
spec/factories/gitaly/commit.rb:17:14: C: FactoryBot/InlineAssociation: Prefer inline association over build. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
author { build(:gitaly_commit_author) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/gitaly/commit.rb:18:17: C: FactoryBot/InlineAssociation: Prefer inline association over build. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
committer { build(:gitaly_commit_author) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/go_module_commits.rb:10:17: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
project { create(:project, :repository) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/go_module_versions.rb:16:11: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
mod { create :go_module }
^^^^^^^^^^^^^^^^^
spec/factories/go_modules.rb:8:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
project { create :project, :repository }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/group_group_links.rb:5:20: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
shared_group { create(:group) }
^^^^^^^^^^^^^^
spec/factories/group_group_links.rb:6:25: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
shared_with_group { create(:group) }
^^^^^^^^^^^^^^
spec/factories/import_export_uploads.rb:5:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
project { create(:project) }
^^^^^^^^^^^^^^^^
spec/factories/merge_requests.rb:240:22: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
deployment { create(:deployment, :review_app) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/notes.rb:11:34: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
author { project&.creator || create(:user) }
^^^^^^^^^^^^^
spec/factories/notes.rb:58:9: C: FactoryBot/InlineAssociation: Prefer inline association over build. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
build(:text_diff_position, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/notes.rb:67:11: C: FactoryBot/InlineAssociation: Prefer inline association over build. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
build(:text_diff_position, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/notes.rb:77:11: C: FactoryBot/InlineAssociation: Prefer inline association over build. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
build(:image_diff_position, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/notes.rb:93:9: C: FactoryBot/InlineAssociation: Prefer inline association over build. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
build(:text_diff_position, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/notes.rb:103:18: C: FactoryBot/InlineAssociation: Prefer inline association over build. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
position { build(:image_diff_position, file: noteable.full_path, diff_refs: noteable.diff_refs) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/packages.rb:132:27: C: FactoryBot/InlineAssociation: Prefer inline association over build. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
conan_metadatum { build(:conan_metadatum, package: nil) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/packages.rb:144:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
package { create(:composer_package) }
^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/packages.rb:169:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
package { create(:pypi_package, without_loaded_metadatum: true) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/packages.rb:174:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
package { create(:nuget_package) }
^^^^^^^^^^^^^^^^^^^^^^
spec/factories/packages.rb:182:20: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
package_file { create(:conan_package_file, :conan_recipe_file, without_loaded_metadatum: true) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/packages.rb:191:22: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
package_file { create(:conan_package_file, :conan_package, without_loaded_metadatum: true) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/packages.rb:204:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
package { create(:nuget_package) }
^^^^^^^^^^^^^^^^^^^^^^
spec/factories/packages.rb:205:18: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
dependency { create(:packages_dependency) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/packages.rb:216:23: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
dependency_link { create(:packages_dependency_link) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/packages/package_file.rb:18:17: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
package { create(:conan_package, without_package_files: true) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/prometheus_alert.rb:10:7: C: FactoryBot/InlineAssociation: Prefer inline association over build. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
build(:environment, project: alert.project)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/prometheus_alert.rb:14:7: C: FactoryBot/InlineAssociation: Prefer inline association over build. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
build(:prometheus_metric, project: alert.project)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/resource_label_events.rb:7:32: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
user { issuable&.author || create(:user) }
^^^^^^^^^^^^^
spec/factories/resource_milestone_event.rb:5:34: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
issue { merge_request.nil? ? create(:issue) : nil }
^^^^^^^^^^^^^^
spec/factories/resource_milestone_event.rb:10:54: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
user { issue&.author || merge_request&.author || create(:user) }
^^^^^^^^^^^^^
spec/factories/resource_state_event.rb:5:34: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
issue { merge_request.nil? ? create(:issue) : nil }
^^^^^^^^^^^^^^
spec/factories/resource_state_event.rb:8:54: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
user { issue&.author || merge_request&.author || create(:user) }
^^^^^^^^^^^^^
spec/factories/sent_notifications.rb:7:16: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
noteable { create(:issue, project: project) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/serverless/domain.rb:6:33: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
serverless_domain_cluster { create(:serverless_domain_cluster) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/serverless/domain.rb:7:19: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
environment { create(:environment) }
^^^^^^^^^^^^^^^^^^^^
spec/factories/serverless/domain_cluster.rb:5:20: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
pages_domain { create(:pages_domain) }
^^^^^^^^^^^^^^^^^^^^^
spec/factories/serverless/domain_cluster.rb:6:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
knative { create(:clusters_applications_knative) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/serverless/domain_cluster.rb:7:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
creator { create(:user) }
^^^^^^^^^^^^^
spec/factories/terraform/state.rb:5:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
project { create(:project) }
^^^^^^^^^^^^^^^^
spec/factories/terraform/state.rb:17:24: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
locked_by_user { create(:user) }
^^^^^^^^^^^^^
spec/factories/uploads.rb:5:13: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
model { create(:project) }
^^^^^^^^^^^^^^^^
spec/factories/uploads.rb:23:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
model { create(:personal_snippet) }
^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/uploads.rb:49:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
model { create(:group) }
^^^^^^^^^^^^^^
spec/factories/uploads.rb:57:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
model { create(:appearance) }
^^^^^^^^^^^^^^^^^^^
spec/factories/uploads.rb:65:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
model { create(:note) }
^^^^^^^^^^^^^
spec/factories/uploads.rb:71:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
model { create(:design_action) }
^^^^^^^^^^^^^^^^^^^^^^
spec/factories/wiki_pages.rb:42:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
project { create(:project) }
^^^^^^^^^^^^^^^^
spec/factories/wiki_pages.rb:46:21: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
wiki_page { create(:wiki_page, container: project) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/factories/wiki_pages.rb:49:54: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
project { @overrides[:wiki_page]&.container || create(:project) }
^^^^^^^^^^^^^^^^
spec/factories/wiki_pages.rb:61:22: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
wiki_page_meta { create(:wiki_page_meta) }
^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/ci/reports/security/reports.rb:6:16: C: FactoryBot/InlineAssociation: Prefer inline association over build. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
pipeline { build(:ci_pipeline) }
^^^^^^^^^^^^^^^^^^^
ee/spec/factories/geo/event_log.rb:100:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
project { create(:project, :repository) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/geo/event_log.rb:112:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
project { create(:project, :repository) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/geo/event_log.rb:123:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
project { create(:project, :repository) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/geo/event_log.rb:130:18: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
lfs_object { create(:lfs_object, :with_file) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/geo/event_log.rb:142:20: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
job_artifact { create(:ci_job_artifact, :archive) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/geo/event_log.rb:153:14: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
upload { create(:upload) }
^^^^^^^^^^^^^^^
ee/spec/factories/geo/event_log.rb:160:16: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
upload { create(:upload, :issuable_upload) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/geo/event_log.rb:164:16: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
upload { create(:upload, :personal_snippet) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/geo/event_log.rb:168:16: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
upload { create(:upload, :namespace_upload) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/groups.rb:53:23: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
deleting_user { create(:user) }
^^^^^^^^^^^^^
ee/spec/factories/merge_request_blocks.rb:5:30: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
blocking_merge_request { create(:merge_request) }
^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/merge_request_blocks.rb:6:29: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
blocked_merge_request { create(:merge_request) }
^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/resource_iteration_event.rb:5:34: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
issue { merge_request.nil? ? create(:issue) : nil }
^^^^^^^^^^^^^^
ee/spec/factories/resource_iteration_event.rb:9:54: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
user { issue&.author || merge_request&.author || create(:user) }
^^^^^^^^^^^^^
ee/spec/factories/resource_weight_events.rb:5:13: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
issue { create(:issue) }
^^^^^^^^^^^^^^
ee/spec/factories/resource_weight_events.rb:6:29: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
user { issue&.author || create(:user) }
^^^^^^^^^^^^^
ee/spec/factories/vulnerabilities/feedback.rb:15:16: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
pipeline { create(:ci_pipeline, project: project) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/vulnerabilities/feedback.rb:33:15: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
issue { create(:issue, project: project) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/spec/factories/vulnerabilities/feedback.rb:38:23: C: FactoryBot/InlineAssociation: Prefer inline association over create. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#factories
merge_request { create(:merge_request, source_project: project) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
386 files inspected, 86 offenses detected
Check-list
-
Make sure this MR enables a static analysis check rule for new usage but ignores current offenses -
Mention this proposal in the relevant Slack channels (e.g. #development
,#backend
,#frontend
) - [-] If there is a choice to make between two potential styles, set up an emoji vote in the MR:
- CHOICE_A:
🅰 - CHOICE_B:
🅱 - Vote yourself for both choices so that people know these are the choices
- CHOICE_A:
-
The MR doesn't have significant objections, and is getting a majority of 👍 vs👎 (remember that we don't need to reach a consensus) - [-] (If applicable) One style is getting a majority of vote (compared to the other choice)
- [-] (If applicable) Update the MR with the chosen style
-
Create a follow-up issue to fix the current offenses as a separate iteration: #267606 (closed) -
Follow the review process as usual -
Once approved and merged by a maintainer, mention it again: -
In the relevant Slack channels (e.g. #development
,#backend
,#frontend
) -
(Optional depending on the impact of the change) In the Engineering Week in Review
-
Edited by Peter Leitzen