debian-mirror-gitlab/spec/factories/milestones.rb

59 lines
1.4 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
FactoryBot.define do
2020-04-22 19:07:51 +05:30
factory :milestone, traits: [:has_internal_id] do
2016-06-02 11:05:42 +05:30
title
2017-09-10 17:25:29 +05:30
transient do
2019-12-21 20:55:43 +05:30
project { nil }
group { nil }
project_id { nil }
group_id { nil }
resource_parent { nil }
2017-09-10 17:25:29 +05:30
end
2016-06-02 11:05:42 +05:30
2016-11-03 12:29:30 +05:30
trait :active do
2019-12-21 20:55:43 +05:30
state { "active" }
2016-11-03 12:29:30 +05:30
end
2016-06-02 11:05:42 +05:30
trait :closed do
2019-12-21 20:55:43 +05:30
state { "closed" }
2016-06-02 11:05:42 +05:30
end
2018-11-20 20:47:30 +05:30
trait :with_dates do
start_date { Date.new(2000, 1, 1) }
due_date { Date.new(2000, 1, 30) }
end
2020-04-22 19:07:51 +05:30
trait :on_project do
project
end
trait :on_group do
group
end
2017-09-10 17:25:29 +05:30
after(:build, :stub) do |milestone, evaluator|
if evaluator.group
milestone.group = evaluator.group
elsif evaluator.group_id
milestone.group_id = evaluator.group_id
elsif evaluator.project
milestone.project = evaluator.project
elsif evaluator.project_id
milestone.project_id = evaluator.project_id
2019-12-21 20:55:43 +05:30
elsif evaluator.resource_parent
id = evaluator.resource_parent.id
evaluator.resource_parent.is_a?(Group) ? evaluator.group_id = id : evaluator.project_id = id
2017-09-10 17:25:29 +05:30
else
milestone.project = create(:project)
end
end
2016-11-03 12:29:30 +05:30
factory :active_milestone, traits: [:active]
2016-06-02 11:05:42 +05:30
factory :closed_milestone, traits: [:closed]
2020-04-22 19:07:51 +05:30
factory :project_milestone, traits: [:on_project]
factory :group_milestone, traits: [:on_group]
2016-06-02 11:05:42 +05:30
end
end