2020-04-27 05:09:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
FactoryBot.define do
|
2020-05-15 05:07:59 -04:00
|
|
|
sequence(:sequential_date) do |n|
|
|
|
|
n.days.from_now
|
|
|
|
end
|
|
|
|
|
2020-05-14 08:08:21 -04:00
|
|
|
factory :iteration do
|
2020-04-27 05:09:51 -04:00
|
|
|
title
|
2020-05-15 05:07:59 -04:00
|
|
|
start_date { generate(:sequential_date) }
|
|
|
|
due_date { generate(:sequential_date) }
|
2020-04-27 05:09:51 -04:00
|
|
|
|
|
|
|
transient do
|
|
|
|
project { nil }
|
|
|
|
group { nil }
|
|
|
|
project_id { nil }
|
|
|
|
group_id { nil }
|
|
|
|
resource_parent { nil }
|
|
|
|
end
|
|
|
|
|
2020-05-15 05:07:59 -04:00
|
|
|
trait :upcoming do
|
|
|
|
state_enum { Iteration::STATE_ENUM_MAP[:upcoming] }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :started do
|
|
|
|
state_enum { Iteration::STATE_ENUM_MAP[:started] }
|
2020-04-27 05:09:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :closed do
|
2020-05-15 05:07:59 -04:00
|
|
|
state_enum { Iteration::STATE_ENUM_MAP[:closed] }
|
2020-04-27 05:09:51 -04:00
|
|
|
end
|
|
|
|
|
2020-05-15 05:07:59 -04:00
|
|
|
trait(:skip_future_date_validation) do
|
|
|
|
after(:stub, :build) do |iteration|
|
|
|
|
iteration.skip_future_date_validation = true
|
|
|
|
end
|
2020-04-27 05:09:51 -04:00
|
|
|
end
|
|
|
|
|
2020-05-14 08:08:21 -04:00
|
|
|
after(:build, :stub) do |iteration, evaluator|
|
2020-04-27 05:09:51 -04:00
|
|
|
if evaluator.group
|
2020-05-14 08:08:21 -04:00
|
|
|
iteration.group = evaluator.group
|
2020-04-27 05:09:51 -04:00
|
|
|
elsif evaluator.group_id
|
2020-05-14 08:08:21 -04:00
|
|
|
iteration.group_id = evaluator.group_id
|
2020-04-27 05:09:51 -04:00
|
|
|
elsif evaluator.project
|
2020-05-14 08:08:21 -04:00
|
|
|
iteration.project = evaluator.project
|
2020-04-27 05:09:51 -04:00
|
|
|
elsif evaluator.project_id
|
2020-05-14 08:08:21 -04:00
|
|
|
iteration.project_id = evaluator.project_id
|
2020-04-27 05:09:51 -04: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 08:08:21 -04:00
|
|
|
iteration.project = create(:project)
|
2020-04-27 05:09:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-15 05:07:59 -04:00
|
|
|
factory :upcoming_iteration, traits: [:upcoming]
|
|
|
|
factory :started_iteration, traits: [:started]
|
2020-05-14 08:08:21 -04:00
|
|
|
factory :closed_iteration, traits: [:closed]
|
2020-04-27 05:09:51 -04:00
|
|
|
end
|
|
|
|
end
|