Commit 4b8c0ab7 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider

Merge branch...

Merge branch 'fix/semester_process_review_with_mission_end_set_after_process_created' into 'develop'

Fix/semester process review with mission end set after process created

See merge request !943
parents d0add18a dc29969d
Pipeline #41212 passed with stage
in 37 minutes and 5 seconds
class SemesterProcessVolunteerMission < ApplicationRecord
include MissionEitherOneRelation
delegate :volunteer, to: :semester_process_volunteer
belongs_to :semester_process_volunteer
delegate :volunteer, to: :semester_process_volunteer
has_one :semester_process, through: :semester_process_volunteer
delegate :semester, to: :semester_process
scope :need_feedback, lambda {
includes(:assignment, :group_assignment)
.where("(semester_process_volunteer_missions.assignment_id IS NOT NULL AND
assignments.period_end IS NULL)
OR
(semester_process_volunteer_missions.group_assignment_id IS NOT NULL AND
group_assignments.period_end is NULL)")
.references(:assignments, :group_assignments)
includes(:assignment, :group_assignment, semester_process_volunteer: [:semester_process])
.references(:assignments, :group_assignments, semester_process_volunteer: [:semester_process])
.where(<<-SQL.squish)
(semester_process_volunteer_missions.assignment_id IS NOT NULL AND
(assignments.period_end IS NULL
OR
assignments.period_end > lower(semester_processes.semester))
) OR (semester_process_volunteer_missions.group_assignment_id IS NOT NULL AND
(group_assignments.period_end IS NULL
OR
group_assignments.period_end > lower(semester_processes.semester))
)
SQL
}
end
......@@ -10,6 +10,28 @@ class SemesterProcessVolunteerMissionTest < ActiveSupport::TestCase
semester_process_volunteer: @sem_proc_vol)
end
test '#need_feedback' do
@sem_proc_vol.semester_process.update!(semester: time_z(2018, 6, 1)..time_z(2018, 10, 31))
@assignment.update!(period_end: nil)
@group_assignment.update!(period_end: nil)
mission1 = create(:semester_process_volunteer_mission, mission: @assignment, semester_process_volunteer: @sem_proc_vol)
mission2 = create(:semester_process_volunteer_mission, mission: @group_assignment, semester_process_volunteer: @sem_proc_vol)
assert_includes @sem_proc_vol.semester_process_volunteer_missions.need_feedback, mission1
assert_includes @sem_proc_vol.semester_process_volunteer_missions.need_feedback, mission2
@assignment.update!(period_end: time_z(2018, 5, 1))
@group_assignment.update!(period_end: time_z(2017, 5, 1))
assert_not_includes @sem_proc_vol.semester_process_volunteer_missions.need_feedback, mission1
assert_not_includes @sem_proc_vol.semester_process_volunteer_missions.need_feedback, mission2
@assignment.update!(period_end: time_z(2018, 7, 1))
@group_assignment.update!(period_end: time_z(2018, 8, 1))
assert_includes @sem_proc_vol.semester_process_volunteer_missions.need_feedback, mission1
assert_includes @sem_proc_vol.semester_process_volunteer_missions.need_feedback, mission2
@assignment.update!(period_end: time_z(2018, 12, 1))
@group_assignment.update!(period_end: time_z(2019, 1, 20))
assert_includes @sem_proc_vol.semester_process_volunteer_missions.need_feedback, mission1
assert_includes @sem_proc_vol.semester_process_volunteer_missions.need_feedback, mission2
end
test 'its_invalid_if_no_mission_is_assigned' do
assert_not @subject.valid?
assert_equal :insuficient_relation, @subject.errors.details[:assignment].first[:error]
......
......@@ -119,9 +119,13 @@ class SemesterProcessVolunteerTest < ActiveSupport::TestCase
assert_equal 2, subject.semester_process_volunteer_missions.size
assert_equal 1, subject.semester_process_volunteer_missions.need_feedback.size
assert_equal 1, semester_process.semester_process_volunteers.active_missions.size
@group_assignment.update(period_end: time_z(2018, 7, 15))
@group_assignment.update(period_end: time_z(2017, 10, 31))
assert_equal 2, subject.semester_process_volunteer_missions.size
assert_equal 0, subject.semester_process_volunteer_missions.need_feedback.size
assert_equal 0, semester_process.semester_process_volunteers.active_missions.size
@group_assignment.update(period_end: time_z(2018, 7, 15))
assert_equal 2, subject.semester_process_volunteer_missions.size
assert_equal 1, subject.semester_process_volunteer_missions.need_feedback.size
assert_equal 0, semester_process.semester_process_volunteers.active_missions.size
end
end
Markdown is supported
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