2020-04-27 09:09:51 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
FactoryBot.define do
|
2020-05-14 12:08:21 +00:00
|
|
|
factory :iteration do
|
2020-04-27 09:09:51 +00:00
|
|
|
title
|
|
|
|
|
|
|
|
transient do
|
|
|
|
project { nil }
|
|
|
|
group { nil }
|
|
|
|
project_id { nil }
|
|
|
|
group_id { nil }
|
|
|
|
resource_parent { nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :active do
|
2020-05-14 12:08:21 +00:00
|
|
|
state { Iteration::STATE_ID_MAP[:active] }
|
2020-04-27 09:09:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :closed do
|
2020-05-14 12:08:21 +00:00
|
|
|
state { Iteration::STATE_ID_MAP[:closed] }
|
2020-04-27 09:09:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_dates do
|
|
|
|
start_date { Date.new(2000, 1, 1) }
|
|
|
|
due_date { Date.new(2000, 1, 30) }
|
|
|
|
end
|
|
|
|
|
2020-05-14 12:08:21 +00:00
|
|
|
after(:build, :stub) do |iteration, evaluator|
|
2020-04-27 09:09:51 +00:00
|
|
|
if evaluator.group
|
2020-05-14 12:08:21 +00:00
|
|
|
iteration.group = evaluator.group
|
2020-04-27 09:09:51 +00:00
|
|
|
elsif evaluator.group_id
|
2020-05-14 12:08:21 +00:00
|
|
|
iteration.group_id = evaluator.group_id
|
2020-04-27 09:09:51 +00:00
|
|
|
elsif evaluator.project
|
2020-05-14 12:08:21 +00:00
|
|
|
iteration.project = evaluator.project
|
2020-04-27 09:09:51 +00:00
|
|
|
elsif evaluator.project_id
|
2020-05-14 12:08:21 +00:00
|
|
|
iteration.project_id = evaluator.project_id
|
2020-04-27 09:09:51 +00:00
|
|
|
elsif evaluator.resource_parent
|
|
|
|
id = evaluator.resource_parent.id
|
|
|
|
evaluator.resource_parent.is_a?(Group) ? evaluator.group_id = id : evaluator.project_id = id
|
|
|
|
else
|
2020-05-14 12:08:21 +00:00
|
|
|
iteration.project = create(:project)
|
2020-04-27 09:09:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-14 12:08:21 +00:00
|
|
|
factory :active_iteration, traits: [:active]
|
|
|
|
factory :closed_iteration, traits: [:closed]
|
2020-04-27 09:09:51 +00:00
|
|
|
end
|
|
|
|
end
|