Commit 8ca232bd authored by Heinrich Lee Yu's avatar Heinrich Lee Yu Committed by Eugenia Grieff

Fix factory hooks when building

This skips some hooks when some associations are not persisted. We still
keep them in `after(:build)` because there are still some cases where we
pass persisted associations to `build`
parent 0422c4a6
......@@ -10,15 +10,18 @@ FactoryBot.define do
if cluster.project_type?
cluster_project = cluster.cluster_project
kubernetes_namespace.project = cluster_project.project
kubernetes_namespace.project = cluster_project&.project
kubernetes_namespace.cluster_project = cluster_project
end
kubernetes_namespace.namespace ||=
Gitlab::Kubernetes::DefaultNamespace.new(
cluster,
project: kubernetes_namespace.project
).from_environment_slug(kubernetes_namespace.environment&.slug)
if kubernetes_namespace.project
kubernetes_namespace.namespace ||=
Gitlab::Kubernetes::DefaultNamespace.new(
cluster,
project: kubernetes_namespace.project
).from_environment_slug(kubernetes_namespace.environment&.slug)
end
kubernetes_namespace.service_account_name ||= "#{kubernetes_namespace.namespace}-service-account"
end
......
......@@ -25,7 +25,7 @@ FactoryBot.define do
factory :draft_note_on_discussion, traits: [:on_discussion]
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
......@@ -14,7 +14,7 @@ FactoryBot.define do
end
after(:build) do |uploader, evaluator|
uploader.store!(evaluator.file)
uploader.store!(evaluator.file) if evaluator.project&.persisted?
end
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