diff --git a/app/models/work_week.rb b/app/models/work_week.rb index 5bc0cbe..a33aad4 100644 --- a/app/models/work_week.rb +++ b/app/models/work_week.rb @@ -14,8 +14,8 @@ class WorkWeek < ApplicationRecord validate :no_future_actual_hours def is_future_work_week? - Date.today.year < year || ( - year == Date.today.year && cweek > Date.today.cweek + Date.today.cwyear < year || ( + year == Date.today.cwyear && cweek > Date.today.cweek ) end @@ -39,6 +39,6 @@ def actual_hours_allowed? return false if year_zero? || cweek_zero? today = Date.today - today.year > year || (today.year == year && today.cweek >= cweek) + today.cwyear > year || (today.cwyear == year && today.cweek >= cweek) end end diff --git a/spec/factories.rb b/spec/factories.rb index f125c4c..9440941 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -92,7 +92,7 @@ factory :work_week do assignment cweek { Date.today.cweek } - year { Date.today.year } + year { Date.today.cwyear } estimated_hours { rand(2..8) } actual_hours { rand(2..8) } diff --git a/spec/graphql/mutations/upsert_work_week_spec.rb b/spec/graphql/mutations/upsert_work_week_spec.rb index 3348e82..2606ba0 100644 --- a/spec/graphql/mutations/upsert_work_week_spec.rb +++ b/spec/graphql/mutations/upsert_work_week_spec.rb @@ -124,7 +124,7 @@ }.to raise_error(ActiveRecord::RecordNotFound) end - it "does not delete a future work week when passed a null or 0 value for estimatedHours" do + it "does not delete a past work week when passed a null or 0 value for estimatedHours if there are actualHours" do query_string = <<-GRAPHQL mutation($assignmentId: ID!, $cweek: Int!, $year: Int!, $actualHours: Int, $estimatedHours: Int) { upsertWorkWeek(assignmentId: $assignmentId, cweek: $cweek, year: $year, actualHours: $actualHours, estimatedHours: $estimatedHours) { @@ -137,9 +137,11 @@ company = create(:company) assignment = tbd_assignment_for_company(company:) user = company.users.first + + past_date = Date.today - 2.months work_week = create(:work_week, - cweek: (Date.today - 1.month).cweek, - year: (Date.today - 1.month).year, + cweek: past_date.cweek, + year: past_date.year, estimated_hours: 10, actual_hours: 10, assignment: @@ -155,13 +157,13 @@ assignmentId: work_week.assignment_id, cweek: work_week.cweek, year: work_week.year, - actualHours: nil, - estimatedHours: nil + estimatedHours: nil, + actualHours: 10 } ) post_result = result["data"]["upsertWorkWeek"] - expect(post_result["actualHours"]).to eq(0) + expect(post_result["actualHours"]).to eq(10) expect(post_result["estimatedHours"]).to eq(0) expect { work_week.reload @@ -297,14 +299,14 @@ variables: { assignmentId: assignment.id, cweek: today.cweek, - year: today.year, + year: today.cwyear, estimatedHours: 15 } ) post_result = result["data"]["upsertWorkWeek"] expect(post_result["cweek"]).to eq(today.cweek) - expect(post_result["year"]).to eq(today.year) + expect(post_result["year"]).to eq(today.cwyear) expect(post_result["actualHours"]).to eq(0) expect(post_result["estimatedHours"]).to eq(15) end diff --git a/spec/models/work_week_spec.rb b/spec/models/work_week_spec.rb index 7488e8f..8dd1538 100644 --- a/spec/models/work_week_spec.rb +++ b/spec/models/work_week_spec.rb @@ -31,12 +31,12 @@ context "#is_future_work_week?" do it "returns true if the work week is in the future" do - work_week = build(:work_week, year: Date.today.year, cweek: Date.today.cweek + 1) + work_week = build(:work_week, year: Date.today.cwyear, cweek: Date.today.cweek + 1) expect(work_week.is_future_work_week?).to be_truthy end it "returns false if the work week is in the past" do - work_week = build(:work_week, year: Date.today.year, cweek: Date.today.cweek - 1) + work_week = build(:work_week, year: Date.today.cwyear, cweek: Date.today.cweek - 1) expect(work_week.is_future_work_week?).to be_falsey end end