Commit bf0daa4c authored by Robert Speicher's avatar Robert Speicher

Merge branch 'parent-strategy-fix-factory-hooks-when-building' into 'master'

Use parent strategy for associations in factories - Factory Hooks

See merge request gitlab-org/gitlab!41376
parents 1016c439 8ca232bd
...@@ -10,15 +10,18 @@ FactoryBot.define do ...@@ -10,15 +10,18 @@ FactoryBot.define do
if cluster.project_type? if cluster.project_type?
cluster_project = cluster.cluster_project cluster_project = cluster.cluster_project
kubernetes_namespace.project = cluster_project.project kubernetes_namespace.project = cluster_project&.project
kubernetes_namespace.cluster_project = cluster_project kubernetes_namespace.cluster_project = cluster_project
end end
if kubernetes_namespace.project
kubernetes_namespace.namespace ||= kubernetes_namespace.namespace ||=
Gitlab::Kubernetes::DefaultNamespace.new( Gitlab::Kubernetes::DefaultNamespace.new(
cluster, cluster,
project: kubernetes_namespace.project project: kubernetes_namespace.project
).from_environment_slug(kubernetes_namespace.environment&.slug) ).from_environment_slug(kubernetes_namespace.environment&.slug)
end
kubernetes_namespace.service_account_name ||= "#{kubernetes_namespace.namespace}-service-account" kubernetes_namespace.service_account_name ||= "#{kubernetes_namespace.namespace}-service-account"
end end
......
...@@ -25,7 +25,7 @@ FactoryBot.define do ...@@ -25,7 +25,7 @@ FactoryBot.define do
factory :draft_note_on_discussion, traits: [:on_discussion] factory :draft_note_on_discussion, traits: [:on_discussion]
trait :on_discussion do trait :on_discussion do
discussion_id { create(:discussion_note_on_merge_request, noteable: merge_request, project: project).discussion_id } discussion_id { association(:discussion_note_on_merge_request, noteable: merge_request, project: project).discussion_id }
end end
end end
end end
...@@ -14,7 +14,7 @@ FactoryBot.define do ...@@ -14,7 +14,7 @@ FactoryBot.define do
end end
after(:build) do |uploader, evaluator| after(:build) do |uploader, evaluator|
uploader.store!(evaluator.file) uploader.store!(evaluator.file) if evaluator.project&.persisted?
end end
initialize_with do initialize_with do
......
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