milestones.rb 1.06 KB
Newer Older
1
FactoryBot.define do
2 3
  factory :milestone do
    title
Felipe Artur's avatar
Felipe Artur committed
4 5 6 7 8 9

    transient do
      project nil
      group nil
      project_id nil
      group_id nil
Felipe Artur's avatar
Felipe Artur committed
10
      parent nil
Felipe Artur's avatar
Felipe Artur committed
11
    end
12

13 14 15 16
    trait :active do
      state "active"
    end

17
    trait :closed do
18
      state "closed"
19 20
    end

21 22 23 24 25
    trait :with_dates do
      start_date { Date.new(2000, 1, 1) }
      due_date { Date.new(2000, 1, 30) }
    end

26
    after(:build, :stub) do |milestone, evaluator|
Felipe Artur's avatar
Felipe Artur committed
27 28 29 30 31 32 33 34
      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
Felipe Artur's avatar
Felipe Artur committed
35 36
      elsif evaluator.parent
        id = evaluator.parent.id
37
        evaluator.parent.is_a?(Group) ? evaluator.group_id = id : evaluator.project_id = id
Felipe Artur's avatar
Felipe Artur committed
38
      else
39
        milestone.project = create(:project)
Felipe Artur's avatar
Felipe Artur committed
40 41 42
      end
    end

43
    factory :active_milestone, traits: [:active]
44 45 46
    factory :closed_milestone, traits: [:closed]
  end
end