semester_process_volunteers.rb 1.37 KB
Newer Older
1
2
3
FactoryBot.define do
  factory :semester_process_volunteer do
    volunteer
Kaspar Vollenweider's avatar
Kaspar Vollenweider committed
4
    semester_process
5
    notes { ['some note', 'another note'] }
Kaspar Vollenweider's avatar
Kaspar Vollenweider committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

    transient do
      add_mission { false }
      mission_count { 1 }
      mission_type { :assignment }
      add_feedbacks { false }
      add_hours { false }
    end

    trait :with_mission do
      transient do
        add_mission { true }
      end
    end

    trait :with_feedbacks do
      transient do
        add_feedbacks { true }
      end
    end

    trait :with_hours do
      transient do
        add_hours { true }
      end
    end

    after(:create) do |spv, evaluator|
      (evaluator.mission_count || 1).times do
        create(:semester_process_volunteer_mission, semester_process_volunteer: spv,
          mission: create(evaluator.mission_type || :assignment, volunteer: spv.volunteer))
      end

      if evaluator.add_feedbacks
        spv.semester_process_volunteer_missions.map do |sem_proc_vol_mission|
          create(:semester_feedback, mission: sem_proc_vol_mission.mission,
            semester_process_volunteer: spv)
        end
      end

      if evaluator.add_hours
        spv.semester_process_volunteer_missions.map do |sem_proc_vol_mission|
          create(:hour, hourable: sem_proc_vol_mission.mission, volunteer: spv.volunteer,
            semester_process_volunteer: spv)
        end
      end
    end
53
54
  end
end