Verified Commit 7284d030 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

fix factories

parent 58acfa96
...@@ -10,6 +10,14 @@ class SemesterFeedback < ApplicationRecord ...@@ -10,6 +10,14 @@ class SemesterFeedback < ApplicationRecord
validate :validate_group_assignment_or_assignment_present validate :validate_group_assignment_or_assignment_present
def mission=(mission)
if mission.class.name == 'Assignment'
self.assignment = mission
else
self.group_assignment = mission
end
end
def mission def mission
group_assignment || assignment group_assignment || assignment
end end
......
...@@ -8,7 +8,7 @@ class SemesterProcessVolunteer < ApplicationRecord ...@@ -8,7 +8,7 @@ class SemesterProcessVolunteer < ApplicationRecord
belongs_to :commited_by, -> { with_deleted }, class_name: 'User', belongs_to :commited_by, -> { with_deleted }, class_name: 'User',
inverse_of: 'semester_processes', optional: true inverse_of: 'semester_processes', optional: true
has_many :semester_process_volunteer_mission, dependent: :destroy has_many :semester_process_volunteer_missions, dependent: :destroy
has_many :semester_feedbacks, dependent: :destroy has_many :semester_feedbacks, dependent: :destroy
has_many :hours, dependent: :nullify has_many :hours, dependent: :nullify
......
...@@ -7,6 +7,14 @@ class SemesterProcessVolunteerMission < ApplicationRecord ...@@ -7,6 +7,14 @@ class SemesterProcessVolunteerMission < ApplicationRecord
validate :validate_group_assignment_or_assignment_present validate :validate_group_assignment_or_assignment_present
def mission=(mission)
if mission.class.name == 'Assignment'
self.assignment = mission
else
self.group_assignment = mission
end
end
def mission def mission
group_assignment || assignment group_assignment || assignment
end end
......
FactoryBot.define do FactoryBot.define do
factory :semester_feedback do factory :semester_feedback do
association :author, factory: :user
semester_process_volunteer semester_process_volunteer
volunteer
goals 'Goals text' goals 'Goals text'
achievements 'Achievements text' achievements 'Achievements text'
future 'Future text' future 'Future text'
comments 'Comments text' comments 'Comments text'
trait :with_assignment do
association :assignment
end
trait :with_group_assignment do
association :group_assignment
end
after(:build) do |sem_fb| after(:build) do |sem_fb|
if sem_fb.assignment.blank? if sem_fb.assignment.blank?
sem_fb.group_assignment ||= FactoryBot.build(:group_assignment) sem_fb.group_assignment ||= FactoryBot.build(:group_assignment, volunteer: sem_fb.volunteer)
end end
sem_fb.volunteer = sem_fb.semester_process_volunteer.volunteer
sem_fb.author = sem_fb.volunteer.user
end end
end end
end end
FactoryBot.define do FactoryBot.define do
factory :semester_process_mail do factory :semester_process_mail do
semester_process_volunteer semester_process_volunteer
association :sent_by, factory: :user
sent_at { Time.zone.local(2018, 8, 12) } sent_at { Time.zone.local(2018, 8, 12) }
subject 'mail subject' subject 'mail subject'
body 'Mail body' body 'Mail body'
after(:build) do |sem_proc_mail|
sem_proc_mail.sent_by = sem_proc_mail.semester_process_volunteer.semester_process.creator
end
end end
end end
...@@ -4,7 +4,8 @@ FactoryBot.define do ...@@ -4,7 +4,8 @@ FactoryBot.define do
after(:build) do |spvm| after(:build) do |spvm|
if spvm.assignment.blank? if spvm.assignment.blank?
spvm.group_assignment ||= FactoryBot.build(:group_assignment) spvm.group_assignment ||= FactoryBot.build(:group_assignment,
volunteer: spvm.semester_process_volunteer.volunteer)
end end
end end
......
FactoryBot.define do FactoryBot.define do
factory :semester_process_volunteer do factory :semester_process_volunteer do
volunteer volunteer
semester_process_volunteer_missions semester_process
hours
semester_feedbacks
notes { ['some note', 'another note'] } notes { ['some note', 'another note'] }
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
end end
end end
...@@ -3,10 +3,25 @@ FactoryBot.define do ...@@ -3,10 +3,25 @@ FactoryBot.define do
association :creator, factory: :user association :creator, factory: :user
mail_subject_template 'mail subject template' mail_subject_template 'mail subject template'
mail_body_template 'mail body template' mail_body_template 'mail body template'
mail_posted_at { Time.zone.local(2018, 6, 10) }
association :mail_posted_by, factory: :user
semester_process_volunteers
semester { Time.zone.local(2017, 12, 1).beginning_of_day..Time.zone.local(2018, 5, 30).end_of_month } semester { Time.zone.local(2017, 12, 1).beginning_of_day..Time.zone.local(2018, 5, 30).end_of_month }
transient do
build_volunteers { false }
end
trait :with_volunteers do
transient do
build_volunteers { true }
volunteers_count { 1 }
end
end
after(:create) do |sem_proc, evaluator|
if evaluator.build_volunteers
evaluator.volunteers_count.times do
create :semester_process_volunteer, :with_mission, semester_process: sem_proc
end
end
end
end end
end end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment