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

fix silly endless loop in filter generator

parent aa80ca7d
......@@ -83,8 +83,7 @@ class BillingExpense < ApplicationRecord
value: last_semester.strftime('%Y-%m-%d'),
text: "#{semester_of_year(last_semester)}. Semester #{semester_display_year(last_semester)}"
}
last_semester.advance(months: - SEMESTER_LENGTH)
last_semester = last_semester.advance(months: -SEMESTER_LENGTH)
end
semesters
......
......@@ -17,20 +17,20 @@ class BillingExpenseTest < ActiveSupport::TestCase
end
test 'create_for' do # rubocop:disable Metrics/BlockLength
travel_to Time.zone.parse('2017-07-12')
travel_to tz_parse('2017-07-12')
volunteer1 = create :volunteer_with_user, bank: 'Bank 1'
other_creator = volunteer1.registrar
assignment1 = create :assignment, volunteer: volunteer1, creator: other_creator
hour1a = create :hour, volunteer: volunteer1, meeting_date: Time.zone.parse('2017-04-02'), hourable: assignment1
hour1b = create :hour, volunteer: volunteer1, meeting_date: Time.zone.parse('2017-05-12'), hourable: assignment1
hour1c = create :hour, volunteer: volunteer1, meeting_date: Time.zone.parse('2017-01-18'), hourable: assignment1
hour1a = create :hour, volunteer: volunteer1, meeting_date: tz_parse('2017-04-02'), hourable: assignment1
hour1b = create :hour, volunteer: volunteer1, meeting_date: tz_parse('2017-05-12'), hourable: assignment1
hour1c = create :hour, volunteer: volunteer1, meeting_date: tz_parse('2017-01-18'), hourable: assignment1
create :billing_expense, volunteer: volunteer1, hours: [hour1c], user: other_creator
volunteer2 = create :volunteer, bank: 'Bank 2'
creator = volunteer2.registrar
group_assignment1 = create :group_assignment, volunteer: volunteer2, creator: creator
hour2 = create :hour, volunteer: volunteer2, hours: 75, meeting_date: Time.zone.parse('2017-03-22'), hourable: group_assignment1
hour2 = create :hour, volunteer: volunteer2, hours: 75, meeting_date: tz_parse('2017-03-22'), hourable: group_assignment1
assert_equal 1, BillingExpense.count
assert_equal 1, volunteer1.billing_expenses.count
......@@ -72,10 +72,9 @@ class BillingExpenseTest < ActiveSupport::TestCase
refute_equal creator, hour1c.reviewer
end
test 'generate_semester_filters without hours' do
test 'generate_semester_filters_without_hours' do
semesters = BillingExpense.generate_semester_filters
now = Time.zone.now
if (6..11).cover? now.month
value = "#{now.year}-06-01"
text = "2. Semester #{now.year}"
......@@ -88,7 +87,7 @@ class BillingExpenseTest < ActiveSupport::TestCase
assert_equal [{ q: :semester, value: value, text: text }], semesters
end
test 'generate_semester_filters with hours' do
test 'generate_semester_filters_with_hours' do
hour1 = create :hour, meeting_date: '2014-02-03'
hour2 = create :hour, meeting_date: '2015-06-30'
create :hour, meeting_date: '2017-06-30'
......@@ -104,24 +103,24 @@ class BillingExpenseTest < ActiveSupport::TestCase
], semesters
end
test 'semester scope' do
test 'semester_scope' do
billing_expense1 = create :billing_expense,
hours: [create(:hour, meeting_date: Time.zone.parse('2017-01-12'))]
hours: [create(:hour, meeting_date: tz_parse('2017-01-12'))]
billing_expense2 = create :billing_expense,
hours: [
create(:hour, meeting_date: Time.zone.parse('2017-02-01')),
create(:hour, meeting_date: Time.zone.parse('2017-05-12'))
create(:hour, meeting_date: tz_parse('2017-02-01')),
create(:hour, meeting_date: tz_parse('2017-05-12'))
]
_billing_expense3 = create :billing_expense,
hours: [create(:hour, meeting_date: Time.zone.parse('2016-11-30'))]
hours: [create(:hour, meeting_date: tz_parse('2016-11-30'))]
assert_includes BillingExpense.semester('2016-12-01'), billing_expense1
assert_includes BillingExpense.semester('2016-12-01'), billing_expense2
end
test 'amount can be overwriten' do
test 'amount_can_be_overwriten' do
volunteer = create :volunteer
hour1 = create :hour, volunteer: volunteer, hours: 1
hour2 = create :hour, volunteer: volunteer, hours: 2
......@@ -139,7 +138,7 @@ class BillingExpenseTest < ActiveSupport::TestCase
assert_equal billing_expense.final_amount, billing_expense.amount
end
test 'edited amounts are sortable' do
test 'edited_amounts_are_sortable' do
volunteer1 = create :volunteer
hour1 = create :hour, volunteer: volunteer1, hours: 1
hour2 = create :hour, volunteer: volunteer1, hours: 2
......
......@@ -11,13 +11,13 @@ class HourTest < ActiveSupport::TestCase
end
test 'semester returns hours for a billing_expense semester' do
travel_to Time.zone.parse('2018-05-25')
travel_to tz_parse('2018-05-25')
volunteer = create :volunteer
prev_hour1 = create :hour, volunteer: volunteer, hours: 1, meeting_date: Time.zone.parse('2016-11-15')
prev_hour2 = create :hour, volunteer: volunteer, hours: 1, meeting_date: Time.zone.parse('2016-10-01')
this_hour1 = create :hour, volunteer: volunteer, hours: 1, meeting_date: Time.zone.parse('2016-12-01')
this_hour2 = create :hour, volunteer: volunteer, hours: 1, meeting_date: Time.zone.parse('2017-05-11')
other_hour = create :hour, volunteer: volunteer, hours: 1, meeting_date: Time.zone.parse('2013-11-21')
prev_hour1 = create :hour, volunteer: volunteer, hours: 1, meeting_date: tz_parse('2016-11-15')
prev_hour2 = create :hour, volunteer: volunteer, hours: 1, meeting_date: tz_parse('2016-10-01')
this_hour1 = create :hour, volunteer: volunteer, hours: 1, meeting_date: tz_parse('2016-12-01')
this_hour2 = create :hour, volunteer: volunteer, hours: 1, meeting_date: tz_parse('2017-05-11')
other_hour = create :hour, volunteer: volunteer, hours: 1, meeting_date: tz_parse('2013-11-21')
current_semester_hours = Hour.semester '2016-12-01'
last_semester_hours = Hour.semester '2016-06-01'
......
......@@ -331,18 +331,18 @@ class VolunteerScopesTest < ActiveSupport::TestCase
end
test 'with_billable_hours returns volunteers with billable hours for an optional semester' do
travel_to Time.zone.parse('2017-07-01')
travel_to tz_parse('2017-07-01')
volunteers_in_current_semester_assertion = [@group_offer_member, @has_assignments]
volunteers_in_last_semester_assertion = [@has_multiple, @has_active_and_inactive]
volunteers_in_current_semester_assertion.each do |volunteer|
create :hour, hours: 1, volunteer: volunteer, meeting_date: Time.zone.parse('2017-01-01')
create :hour, hours: 2, volunteer: volunteer, meeting_date: Time.zone.parse('2017-02-02')
create :hour, hours: 1, volunteer: volunteer, meeting_date: tz_parse('2017-01-01')
create :hour, hours: 2, volunteer: volunteer, meeting_date: tz_parse('2017-02-02')
end
volunteers_in_last_semester_assertion.each do |volunteer|
create :hour, hours: 3, volunteer: volunteer, meeting_date: Time.zone.parse('2016-09-01')
create :hour, hours: 4, volunteer: volunteer, meeting_date: Time.zone.parse('2016-11-11')
create :hour, hours: 3, volunteer: volunteer, meeting_date: tz_parse('2016-09-01')
create :hour, hours: 4, volunteer: volunteer, meeting_date: tz_parse('2016-11-11')
end
volunteers_with_billable_hours = Volunteer.with_billable_hours
......
......@@ -3,7 +3,7 @@ require 'application_system_test_case'
class BillingExpensesTest < ApplicationSystemTestCase
def setup
superadmin = create :user
@date = Time.zone.parse('2018-01-01')
@date = tz_parse('2018-01-01')
@volunteer1 = create :volunteer, bank: 'UBS'
@assignment1 = create :assignment, volunteer: @volunteer1
......@@ -30,7 +30,7 @@ class BillingExpensesTest < ApplicationSystemTestCase
group_assignment4 = create :group_assignment, volunteer: @volunteer4
billed_hour4 = create :hour, volunteer: @volunteer4,
hourable: group_assignment4.group_offer,
hours: 5.5, meeting_date: Time.zone.parse('2017-11-01')
hours: 5.5, meeting_date: tz_parse('2017-11-01')
@billing_expense4 = create :billing_expense, volunteer: @volunteer4, hours: [billed_hour4],
created_at: 1.hour.ago
......@@ -96,16 +96,16 @@ class BillingExpensesTest < ApplicationSystemTestCase
test 'new_billing_expense_respects_the_semester_filter' do
volunteer1 = create :volunteer
create :hour, volunteer: volunteer1, hours: 10, meeting_date: Time.zone.parse('2017-11-01')
create :hour, volunteer: volunteer1, hours: 16, meeting_date: Time.zone.parse('2017-10-01')
create :hour, volunteer: volunteer1, hours: 10, meeting_date: tz_parse('2017-11-01')
create :hour, volunteer: volunteer1, hours: 16, meeting_date: tz_parse('2017-10-01')
volunteer2 = create :volunteer, iban: 'pick_out_volunteer'
create :hour, volunteer: volunteer2, hours: 26, meeting_date: Time.zone.parse('2018-02-01')
create :hour, volunteer: volunteer2, hours: 15, meeting_date: Time.zone.parse('2017-11-01')
create :hour, volunteer: volunteer2, hours: 26, meeting_date: tz_parse('2018-02-01')
create :hour, volunteer: volunteer2, hours: 15, meeting_date: tz_parse('2017-11-01')
volunteer3 = create :volunteer
create :hour, volunteer: volunteer3, hours: 1, meeting_date: Time.zone.parse('2018-02-01')
create :hour, volunteer: volunteer3, hours: 2, meeting_date: Time.zone.parse('2018-04-01')
create :hour, volunteer: volunteer3, hours: 1, meeting_date: tz_parse('2018-02-01')
create :hour, volunteer: volunteer3, hours: 2, meeting_date: tz_parse('2018-04-01')
visit billing_expenses_path
......@@ -136,8 +136,8 @@ class BillingExpensesTest < ApplicationSystemTestCase
test 'creating_a_billing_expense_should_respect_semester_filter' do
volunteer = create :volunteer
create :hour, volunteer: volunteer, hours: 26, meeting_date: Time.zone.parse('2017-11-01')
create :hour, volunteer: volunteer, hours: 16, meeting_date: Time.zone.parse('2018-02-01')
create :hour, volunteer: volunteer, hours: 26, meeting_date: tz_parse('2017-11-01')
create :hour, volunteer: volunteer, hours: 16, meeting_date: tz_parse('2018-02-01')
# creating billing_expense for hours in the current semester
visit billing_expenses_path
......@@ -176,8 +176,8 @@ class BillingExpensesTest < ApplicationSystemTestCase
# creating billing_expense for all hours in multiple semesters
volunteer = create :volunteer
create :hour, volunteer: volunteer, hours: 26, meeting_date: Time.zone.parse('2017-11-01')
create :hour, volunteer: volunteer, hours: 16, meeting_date: Time.zone.parse('2018-02-01')
create :hour, volunteer: volunteer, hours: 26, meeting_date: tz_parse('2017-11-01')
create :hour, volunteer: volunteer, hours: 16, meeting_date: tz_parse('2018-02-01')
visit billing_expenses_path
click_link 'Semester: 1. Semester 2018'
......
......@@ -66,7 +66,7 @@ class ActiveSupport::TestCase
end
end
def tz_parse(time_string)
Time.zone.parse(time_string)
def tz_parse(date_string)
Time.zone.parse(date_string)
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