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

fix some tests

parent 44574106
Pipeline #79742 passed with stage
in 12 minutes and 43 seconds
require 'test_helper'
class BillingExpenseTest < ActiveSupport::TestCase
include SemesterScopesGenerators
test 'amount_for' do
assert_equal 150, BillingExpense.amount_for(999)
assert_equal 150, BillingExpense.amount_for(51)
......@@ -89,9 +91,10 @@ class BillingExpenseTest < ActiveSupport::TestCase
test 'generate_semester_filters_with_hours' do
really_destroy_with_deleted(BillingExpense, Hour)
hourable = create(:assignment)
create :billing_expense, hours: [
create(:hour, meeting_date: time_z(2014, 2, 3)),
create(:hour, meeting_date: time_z(2015, 2, 3))
hour_for_meeting_date(time_z(2014, 2, 3), hourable),
hour_for_meeting_date(time_z(2015, 2, 3), hourable)
]
assert_equal [
......@@ -99,26 +102,26 @@ class BillingExpenseTest < ActiveSupport::TestCase
{ q: :semester, value: '2013-12-01', text: '1. Semester 2014' }
], BillingExpense.generate_semester_filters(:billed)
create :hour, meeting_date: '2017-06-30'
create :hour, meeting_date: '2012-06-30'
hour_for_meeting_date(time_z(2017, 6, 30), hourable)
hour_for_meeting_date(time_z(2017, 6, 30), hourable)
assert_equal [
{ q: :semester, value: '2017-06-01', text: '2. Semester 2017' },
{ q: :semester, value: '2012-06-01', text: '2. Semester 2012' }
{ q: :semester, value: '2017-06-01', text: '2. Semester 2017' }
], BillingExpense.generate_semester_filters(:billable)
end
test 'semester_scope' do
hourable = create(:assignment)
billing_expense1 = create :billing_expense,
hours: [create(:hour, meeting_date: time_z(2017, 1, 12))]
hours: [hour_for_meeting_date(time_z(2017, 1, 12), hourable)]
billing_expense2 = create :billing_expense,
hours: [
create(:hour, meeting_date: time_z(2017, 2, 1)),
create(:hour, meeting_date: time_z(2017, 5, 12))
hour_for_meeting_date(time_z(2017, 2, 1), hourable),
hour_for_meeting_date(time_z(2017, 5, 12), hourable)
]
_billing_expense3 = create :billing_expense,
hours: [create(:hour, meeting_date: time_z(2016, 11, 30))]
create :billing_expense,
hours: [hour_for_meeting_date(time_z(2016, 11, 30), hourable)]
assert_includes BillingExpense.semester('2016-12-01'), billing_expense1
assert_includes BillingExpense.semester('2016-12-01'), billing_expense2
......
......@@ -13,29 +13,19 @@ class HourTest < ActiveSupport::TestCase
end
test 'semester returns hours for a billing_expense semester' do
travel_to time_z(2013, 8, 1)
assignment = create :assignment
hours = {
other_hour: hour_for_meeting_date(time_z(2013, 11, 21), assignment)
}
travel_to time_z(2015, 12, 1)
hours = hours.merge(
two_prev_hour1: hour_for_meeting_date(time_z(2015, 12, 1), assignment)
)
travel_to time_z(2016, 12, 1)
hours = hours.merge(
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, 30), assignment),
prev_hour1: hour_for_meeting_date(time_z(2016, 11, 29), assignment),
prev_hour2: hour_for_meeting_date(time_z(2016, 10, 1), assignment),
prev_hour3: hour_for_meeting_date(time_z(2016, 6, 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, 30), assignment)
)
travel_to time_z(2017, 5, 1)
hours = hours.merge(
this_hour2: hour_for_meeting_date(time_z(2017, 4, 10), assignment),
this_hour3: hour_for_meeting_date(time_z(2017, 5, 31), assignment)
)
two_prev_hour3: hour_for_meeting_date(time_z(2016, 5, 30), assignment),
other_hour: hour_for_meeting_date(time_z(2013, 11, 21), assignment)
}
travel_to time_z(2018, 5, 25)
current_semester_hours = Hour.semester '2016-12-01'
......
......@@ -2,8 +2,9 @@ module SemesterScopesGenerators
def hour_for_meeting_date(meeting_date, hourable, hours = 1.0)
before = Time.zone.now
travel_to meeting_date
create :hour, volunteer: hourable.volunteer, hours: hours.to_f, meeting_date: meeting_date,
hour = create :hour, volunteer: hourable.volunteer, hours: hours.to_f, meeting_date: meeting_date,
hourable: hourable.polymorph_url_object
travel_to before
hour
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