From 23e0e5683f7424d5751f4c51b3a30f1a9b159262 Mon Sep 17 00:00:00 2001 From: Peter Leitzen Date: Mon, 15 Mar 2021 19:35:23 +0100 Subject: [PATCH] Fix remaining offenses for FactoryBot/InlineAssociation in Core One offense is disabled to allow `wiki_page_event` factory to work with `build` strategy. --- .rubocop_manual_todo.yml | 10 ---------- spec/factories/atlassian_identities.rb | 2 +- spec/factories/events.rb | 11 +++++++---- spec/factories/git_wiki_commit_details.rb | 2 +- spec/factories/gitaly/commit.rb | 4 ++-- spec/factories/group_group_links.rb | 4 ++-- spec/factories/import_export_uploads.rb | 2 +- 7 files changed, 14 insertions(+), 21 deletions(-) diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index 9b20af55520e31..97217081e29d56 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -41,16 +41,6 @@ Graphql/Descriptions: - 'ee/app/graphql/types/vulnerability_severity_enum.rb' - 'ee/app/graphql/types/vulnerability_state_enum.rb' -# WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/267606 -FactoryBot/InlineAssociation: - Exclude: - - 'spec/factories/atlassian_identities.rb' - - 'spec/factories/events.rb' - - 'spec/factories/git_wiki_commit_details.rb' - - 'spec/factories/gitaly/commit.rb' - - 'spec/factories/group_group_links.rb' - - 'spec/factories/import_export_uploads.rb' - # WIP: See https://gitlab.com/gitlab-org/gitlab/-/issues/220040 Rails/SaveBang: Exclude: diff --git a/spec/factories/atlassian_identities.rb b/spec/factories/atlassian_identities.rb index 698cf4ae7ad215..80420e335a9618 100644 --- a/spec/factories/atlassian_identities.rb +++ b/spec/factories/atlassian_identities.rb @@ -3,7 +3,7 @@ FactoryBot.define do factory :atlassian_identity, class: 'Atlassian::Identity' do extern_uid { generate(:username) } - user { create(:user) } + user { association(:user) } expires_at { 2.weeks.from_now } token { SecureRandom.alphanumeric(1254) } refresh_token { SecureRandom.alphanumeric(45) } diff --git a/spec/factories/events.rb b/spec/factories/events.rb index 6c9f1ba01371a5..c9e4ada3ffa397 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -27,17 +27,20 @@ factory :wiki_page_event do action { :created } + # rubocop: disable FactoryBot/InlineAssociation + # A persistent project is needed to have a wiki page being created properly. project { @overrides[:wiki_page]&.container || create(:project, :wiki_repo) } - target { create(:wiki_page_meta, :for_wiki_page, wiki_page: wiki_page) } + # rubocop: enable FactoryBot/InlineAssociation + target { association(:wiki_page_meta, :for_wiki_page, wiki_page: wiki_page) } transient do - wiki_page { create(:wiki_page, container: project) } + wiki_page { association(:wiki_page, container: project) } end end trait :has_design do transient do - design { create(:design, issue: create(:issue, project: project)) } + design { association(:design, issue: association(:issue, project: project)) } end end @@ -45,7 +48,7 @@ has_design transient do - note { create(:note, author: author, project: project, noteable: design) } + note { association(:note, author: author, project: project, noteable: design) } end action { :commented } diff --git a/spec/factories/git_wiki_commit_details.rb b/spec/factories/git_wiki_commit_details.rb index b35f102fd4dba1..fb3f2954b12934 100644 --- a/spec/factories/git_wiki_commit_details.rb +++ b/spec/factories/git_wiki_commit_details.rb @@ -5,7 +5,7 @@ skip_create transient do - author { create(:user) } + author { association(:user) } end sequence(:message) { |n| "Commit message #{n}" } diff --git a/spec/factories/gitaly/commit.rb b/spec/factories/gitaly/commit.rb index 2ed201e9aacf95..4e8220e449a58d 100644 --- a/spec/factories/gitaly/commit.rb +++ b/spec/factories/gitaly/commit.rb @@ -14,7 +14,7 @@ subject { "My commit" } body { subject + "\nMy body" } - author { build(:gitaly_commit_author) } - committer { build(:gitaly_commit_author) } + author { association(:gitaly_commit_author) } + committer { association(:gitaly_commit_author) } end end diff --git a/spec/factories/group_group_links.rb b/spec/factories/group_group_links.rb index 6f98886faffb3d..2a582d8525b0d5 100644 --- a/spec/factories/group_group_links.rb +++ b/spec/factories/group_group_links.rb @@ -2,8 +2,8 @@ FactoryBot.define do factory :group_group_link do - shared_group { create(:group) } - shared_with_group { create(:group) } + shared_group { association(:group) } + shared_with_group { association(:group) } group_access { Gitlab::Access::DEVELOPER } trait(:guest) { group_access { Gitlab::Access::GUEST } } diff --git a/spec/factories/import_export_uploads.rb b/spec/factories/import_export_uploads.rb index 8521411e0e8146..e1dd0c10ff266d 100644 --- a/spec/factories/import_export_uploads.rb +++ b/spec/factories/import_export_uploads.rb @@ -2,6 +2,6 @@ FactoryBot.define do factory :import_export_upload do - project { create(:project) } + project { association(:project) } end end -- GitLab