Commit 23e0e568 authored by Peter Leitzen's avatar Peter Leitzen

Fix remaining offenses for FactoryBot/InlineAssociation in Core

One offense is disabled to allow `wiki_page_event` factory to work
with `build` strategy.
parent 6ce88e04
...@@ -41,16 +41,6 @@ Graphql/Descriptions: ...@@ -41,16 +41,6 @@ Graphql/Descriptions:
- 'ee/app/graphql/types/vulnerability_severity_enum.rb' - 'ee/app/graphql/types/vulnerability_severity_enum.rb'
- 'ee/app/graphql/types/vulnerability_state_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 # WIP: See https://gitlab.com/gitlab-org/gitlab/-/issues/220040
Rails/SaveBang: Rails/SaveBang:
Exclude: Exclude:
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
FactoryBot.define do FactoryBot.define do
factory :atlassian_identity, class: 'Atlassian::Identity' do factory :atlassian_identity, class: 'Atlassian::Identity' do
extern_uid { generate(:username) } extern_uid { generate(:username) }
user { create(:user) } user { association(:user) }
expires_at { 2.weeks.from_now } expires_at { 2.weeks.from_now }
token { SecureRandom.alphanumeric(1254) } token { SecureRandom.alphanumeric(1254) }
refresh_token { SecureRandom.alphanumeric(45) } refresh_token { SecureRandom.alphanumeric(45) }
......
...@@ -27,17 +27,20 @@ FactoryBot.define do ...@@ -27,17 +27,20 @@ FactoryBot.define do
factory :wiki_page_event do factory :wiki_page_event do
action { :created } 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) } 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 transient do
wiki_page { create(:wiki_page, container: project) } wiki_page { association(:wiki_page, container: project) }
end end
end end
trait :has_design do trait :has_design do
transient do transient do
design { create(:design, issue: create(:issue, project: project)) } design { association(:design, issue: association(:issue, project: project)) }
end end
end end
...@@ -45,7 +48,7 @@ FactoryBot.define do ...@@ -45,7 +48,7 @@ FactoryBot.define do
has_design has_design
transient do transient do
note { create(:note, author: author, project: project, noteable: design) } note { association(:note, author: author, project: project, noteable: design) }
end end
action { :commented } action { :commented }
......
...@@ -5,7 +5,7 @@ FactoryBot.define do ...@@ -5,7 +5,7 @@ FactoryBot.define do
skip_create skip_create
transient do transient do
author { create(:user) } author { association(:user) }
end end
sequence(:message) { |n| "Commit message #{n}" } sequence(:message) { |n| "Commit message #{n}" }
......
...@@ -14,7 +14,7 @@ FactoryBot.define do ...@@ -14,7 +14,7 @@ FactoryBot.define do
subject { "My commit" } subject { "My commit" }
body { subject + "\nMy body" } body { subject + "\nMy body" }
author { build(:gitaly_commit_author) } author { association(:gitaly_commit_author) }
committer { build(:gitaly_commit_author) } committer { association(:gitaly_commit_author) }
end end
end end
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
FactoryBot.define do FactoryBot.define do
factory :group_group_link do factory :group_group_link do
shared_group { create(:group) } shared_group { association(:group) }
shared_with_group { create(:group) } shared_with_group { association(:group) }
group_access { Gitlab::Access::DEVELOPER } group_access { Gitlab::Access::DEVELOPER }
trait(:guest) { group_access { Gitlab::Access::GUEST } } trait(:guest) { group_access { Gitlab::Access::GUEST } }
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
FactoryBot.define do FactoryBot.define do
factory :import_export_upload do factory :import_export_upload do
project { create(:project) } project { association(:project) }
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment