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

final fix for hour semester scope and more extensive test for semester scope

parent ad95ef75
Pipeline #22973 passed with stage
in 40 minutes and 51 seconds
......@@ -19,14 +19,15 @@ class Hour < ApplicationRecord
scope :billable, (-> { where(billing_expense: nil) })
scope :billed, (-> { where.not(billing_expense: nil) })
scope :semester, lambda { |date = nil|
if date.present?
date = Time.zone.parse(date) unless date.is_a? Time
return if date.blank?
date_between_inclusion(:meeting_date, date,
date.advance(months: BillingExpense::SEMESTER_LENGTH))
else
all
end
return all if date.blank?
date = Time.zone.parse(date) unless date.is_a? Time
return all if date.blank?
semester_with_date(date)
}
scope :semester_with_date, lambda { |date|
date_between_inclusion(:meeting_date, date.advance(days: 1),
date.advance(months: BillingExpense::SEMESTER_LENGTH))
}
scope :since_last_submitted, lambda { |submitted_at|
......
......@@ -12,31 +12,65 @@ class HourTest < ActiveSupport::TestCase
test 'semester returns hours for a billing_expense semester' do
travel_to time_z(2018, 5, 25)
volunteer = create :volunteer
prev_hour1 = create :hour, volunteer: volunteer, hours: 1, meeting_date: time_z(2016, 11, 15)
prev_hour2 = create :hour, volunteer: volunteer, hours: 1, meeting_date: time_z(2016, 10, 1)
this_hour1 = create :hour, volunteer: volunteer, hours: 1, meeting_date: time_z(2016, 12, 1)
this_hour2 = create :hour, volunteer: volunteer, hours: 1, meeting_date: time_z(2017, 5, 11)
other_hour = create :hour, volunteer: volunteer, hours: 1, meeting_date: time_z(2013, 11, 21)
assignment = create :assignment
hours = {
this_hour1: hour_for_meeting_date(time_z(2016, 12, 1), assignment),
this_hour2: hour_for_meeting_date(time_z(2017, 4, 10), assignment),
this_hour3: hour_for_meeting_date(time_z(2017, 5, 31), assignment),
prev_hour1: hour_for_meeting_date(time_z(2016, 11, 15), assignment),
prev_hour2: hour_for_meeting_date(time_z(2016, 10, 1), assignment),
prev_hour3: hour_for_meeting_date(time_z(2016, 7, 1), assignment),
two_prev_hour1: hour_for_meeting_date(time_z(2015, 12, 1), assignment),
two_prev_hour2: hour_for_meeting_date(time_z(2016, 4, 10), assignment),
two_prev_hour3: hour_for_meeting_date(time_z(2016, 5, 31), assignment),
other_hour: hour_for_meeting_date(time_z(2013, 11, 21), assignment)
}
current_semester_hours = Hour.semester '2016-12-01'
last_semester_hours = Hour.semester '2016-06-01'
last_first_semester_hours = Hour.semester '2015-12-01'
all_semester_hours = Hour.semester
assert_includes current_semester_hours, this_hour1
assert_includes current_semester_hours, this_hour2
assert_not_includes current_semester_hours, prev_hour1
assert_not_includes current_semester_hours, prev_hour2
assert_not_includes current_semester_hours, other_hour
assert_includes current_semester_hours, hours[:this_hour1]
assert_includes current_semester_hours, hours[:this_hour2]
assert_includes current_semester_hours, hours[:this_hour3]
assert_not_includes current_semester_hours, hours[:prev_hour1]
assert_not_includes current_semester_hours, hours[:prev_hour2]
assert_not_includes current_semester_hours, hours[:prev_hour3]
assert_not_includes current_semester_hours, hours[:two_prev_hour1]
assert_not_includes current_semester_hours, hours[:two_prev_hour2]
assert_not_includes current_semester_hours, hours[:two_prev_hour3]
assert_not_includes current_semester_hours, hours[:other_hour]
assert_includes last_semester_hours, prev_hour1
assert_includes last_semester_hours, prev_hour2
assert_not_includes last_semester_hours, this_hour1
assert_not_includes last_semester_hours, this_hour2
assert_not_includes last_semester_hours, other_hour
assert_not_includes last_semester_hours, hours[:this_hour1]
assert_not_includes last_semester_hours, hours[:this_hour2]
assert_not_includes last_semester_hours, hours[:this_hour3]
assert_includes last_semester_hours, hours[:prev_hour1]
assert_includes last_semester_hours, hours[:prev_hour2]
assert_includes last_semester_hours, hours[:prev_hour3]
assert_not_includes last_semester_hours, hours[:two_prev_hour1]
assert_not_includes last_semester_hours, hours[:two_prev_hour2]
assert_not_includes last_semester_hours, hours[:two_prev_hour3]
assert_not_includes last_semester_hours, hours[:other_hour]
[prev_hour1, prev_hour2, this_hour1, this_hour2, other_hour].map do |hour|
assert_not_includes last_first_semester_hours, hours[:this_hour1]
assert_not_includes last_first_semester_hours, hours[:this_hour2]
assert_not_includes last_first_semester_hours, hours[:this_hour3]
assert_not_includes last_first_semester_hours, hours[:prev_hour1]
assert_not_includes last_first_semester_hours, hours[:prev_hour2]
assert_not_includes last_first_semester_hours, hours[:prev_hour3]
assert_includes last_first_semester_hours, hours[:two_prev_hour1]
assert_includes last_first_semester_hours, hours[:two_prev_hour2]
assert_includes last_first_semester_hours, hours[:two_prev_hour3]
assert_not_includes last_first_semester_hours, hours[:other_hour]
hours.values.each do |hour|
assert_includes all_semester_hours, hour
end
end
def hour_for_meeting_date(meeting_date, assignment)
create :hour, volunteer: assignment.volunteer, hours: 1, meeting_date: meeting_date,
hourable: assignment
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