BigW Consortium Gitlab

milestones.rb 967 Bytes
Newer Older
1 2 3
FactoryGirl.define do
  factory :milestone do
    title
Felipe Artur committed
4 5 6 7 8 9

    transient do
      project nil
      group nil
      project_id nil
      group_id nil
Felipe Artur committed
10
      parent nil
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
    after(:build, :stub) do |milestone, evaluator|
Felipe Artur committed
22 23 24 25 26 27 28 29
      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 committed
30 31 32
      elsif evaluator.parent
        id = evaluator.parent.id
        evaluator.parent.is_a?(Group) ? board.group_id = id : evaluator.project_id = id
Felipe Artur committed
33
      else
34
        milestone.project = create(:project)
Felipe Artur committed
35 36 37
      end
    end

38
    factory :active_milestone, traits: [:active]
39 40 41
    factory :closed_milestone, traits: [:closed]
  end
end