Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/factories/work_item/work_item_types.rb')
-rw-r--r--spec/factories/work_item/work_item_types.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/spec/factories/work_item/work_item_types.rb b/spec/factories/work_item/work_item_types.rb
index 07d6d685c57..1c586aab59b 100644
--- a/spec/factories/work_item/work_item_types.rb
+++ b/spec/factories/work_item/work_item_types.rb
@@ -8,6 +8,17 @@ FactoryBot.define do
base_type { WorkItem::Type.base_types[:issue] }
icon_name { 'issue-type-issue' }
+ initialize_with do
+ type_base_attributes = attributes.with_indifferent_access.slice(:base_type, :namespace, :namespace_id)
+
+ # Expect base_types to exist on the DB
+ if type_base_attributes.slice(:namespace, :namespace_id).compact.empty?
+ WorkItem::Type.find_or_initialize_by(type_base_attributes).tap { |type| type.assign_attributes(attributes) }
+ else
+ WorkItem::Type.new(attributes)
+ end
+ end
+
trait :default do
namespace { nil }
end