Commit 5fa3bf95 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider

SemesterProcessVolunteerMission#need_feedback scope respects missions with...

SemesterProcessVolunteerMission#need_feedback scope respects missions with period end set after start of semester
parent d0add18a
Pipeline #41130 canceled with stage
in 18 minutes and 13 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)
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
(semester_process_volunteer_missions.group_assignment_id IS NOT NULL AND
group_assignments.period_end is NULL)")
.references(:assignments, :group_assignments)
group_assignments.period_end > lower(semester_processes.semester))
)
SQL
}
end
......@@ -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