Skip to content

Commit

Permalink
Merge pull request #1168 from DFE-Digital/sum-claims-by-policy-with-a…
Browse files Browse the repository at this point in the history
…-block

Fix incorrect summing with claims by policy
  • Loading branch information
pezholio authored Oct 8, 2020
2 parents 95fac1e + 06f6f13 commit 5ef658d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog]

## [Unreleased]

- Fix incorrect summing for claims by policy

## [Release 085] - 2020-10-07

- Update payment email copy
Expand Down
2 changes: 1 addition & 1 deletion app/models/payroll_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def number_of_claims_for_policy(policy)
end

def total_claim_amount_for_policy(policy)
claims.by_policy(policy).sum(:award_amount)
claims.by_policy(policy).sum(&:award_amount)
end

def self.create_with_claims!(claims, attrs = {})
Expand Down
10 changes: 7 additions & 3 deletions spec/models/payroll_run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@
payment_4 = build(:payment, claims: [
build(:claim, :approved, eligibility: build(:student_loans_eligibility, :eligible, student_loan_repayment_amount: 1000))
])
payment_5 = build(:payment, claims: [
build(:claim, :approved, teacher_reference_number: "1234567", bank_sort_code: "123456", bank_account_number: "12345678", eligibility: build(:maths_and_physics_eligibility, :eligible)),
build(:claim, :approved, teacher_reference_number: "1234567", bank_sort_code: "123456", bank_account_number: "12345678", eligibility: build(:student_loans_eligibility, :eligible, student_loan_repayment_amount: 1000))
])

payroll_run = PayrollRun.create!(created_by: user, payments: [payment_1, payment_2, payment_3, payment_4])
payroll_run = PayrollRun.create!(created_by: user, payments: [payment_1, payment_2, payment_3, payment_4, payment_5])

expect(payroll_run.total_claim_amount_for_policy(StudentLoans)).to eq(2500)
expect(payroll_run.total_claim_amount_for_policy(MathsAndPhysics)).to eq(4000)
expect(payroll_run.total_claim_amount_for_policy(StudentLoans)).to eq(3500)
expect(payroll_run.total_claim_amount_for_policy(MathsAndPhysics)).to eq(6000)
end
end

Expand Down

0 comments on commit 5ef658d

Please sign in to comment.