diff options
Diffstat (limited to 'spec/factories/work_items/parent_links.rb')
-rw-r--r-- | spec/factories/work_items/parent_links.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/factories/work_items/parent_links.rb b/spec/factories/work_items/parent_links.rb new file mode 100644 index 00000000000..886aa449a57 --- /dev/null +++ b/spec/factories/work_items/parent_links.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :parent_link, class: 'WorkItems::ParentLink' do + transient do + work_item { nil } + work_item_parent { nil } + end + + after(:build) do |link, evaluator| + link.work_item = evaluator.work_item + link.work_item_parent = evaluator.work_item_parent + + unless link.work_item && link.work_item_parent + project = link.work_item&.project || link.work_item_parent&.project || create(:project) + link.work_item ||= create(:work_item, :task, project: project) + link.work_item_parent ||= create(:work_item, project: project) + end + end + end +end |