From c2c49924a3c95fac724c5581a6a56225c6b0d096 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Thu, 17 Mar 2022 10:00:40 +0000
Subject: [PATCH] Cldc 491 rent and charges validations (part 1) (#388)
* move age validation tests to shared validation spec
* Add brent/tshortfall validation
* update period mappings
* Add scharge validation
* update num of weeks from period mapping
* fix test
* change period mappings in test
* Add tests for floats
* change error message content
* add supported housing scharge validation
* add other landlord validations
* refactor
* refactor validation and tests
* Add supcharg validations and refactor
* add total charge calculations
* move constants
* Fix tests and add missing validation messages
---
app/models/case_log.rb | 12 +-
.../validations/financial_validations.rb | 72 +++
config/forms/2021_2022.json | 126 ++---
config/locales/en.yml | 30 +-
spec/factories/case_log.rb | 4 +-
spec/fixtures/complete_case_log.json | 3 +-
spec/fixtures/exports/case_logs.xml | 6 +-
spec/fixtures/forms/2021_2022.json | 4 +-
spec/models/case_log_spec.rb | 279 ++++++---
.../validations/financial_validations_spec.rb | 529 ++++++++++++++++++
.../validations/household_validations_spec.rb | 56 --
.../validations/shared_validations_spec.rb | 66 +++
12 files changed, 983 insertions(+), 204 deletions(-)
create mode 100644 spec/models/validations/shared_validations_spec.rb
diff --git a/app/models/case_log.rb b/app/models/case_log.rb
index 47f957696..394dd62bf 100644
--- a/app/models/case_log.rb
+++ b/app/models/case_log.rb
@@ -41,7 +41,7 @@ class CaseLog < ApplicationRecord
RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze
HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze
STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
- NUM_OF_WEEKS_FROM_PERIOD = { 0 => 26, 1 => 13, 2 => 12, 3 => 50, 4 => 49, 5 => 48, 6 => 47, 7 => 46, 8 => 52 }.freeze
+ NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52 }.freeze
enum status: STATUS
def form
@@ -91,7 +91,7 @@ class CaseLog < ApplicationRecord
num_of_weeks = NUM_OF_WEEKS_FROM_PERIOD[period]
return unless field_value && num_of_weeks
- field_value / 52 * num_of_weeks
+ (field_value / 52 * num_of_weeks).round(2)
end
def applicable_income_range
@@ -269,6 +269,14 @@ class CaseLog < ApplicationRecord
hb == 3
end
+ def this_landlord?
+ landlord == 1
+ end
+
+ def other_landlord?
+ landlord == 2
+ end
+
private
PIO = Postcodes::IO.new
diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb
index 59a38e3a7..32ed2f1bd 100644
--- a/app/models/validations/financial_validations.rb
+++ b/app/models/validations/financial_validations.rb
@@ -58,4 +58,76 @@ module Validations::FinancialValidations
record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits")
end
end
+
+ def validate_rent_amount(record)
+ if record.brent.present? && record.tshortfall.present? && record.brent < record.tshortfall * 2
+ record.errors.add :brent, I18n.t("validations.financial.rent.less_than_double_shortfall", tshortfall: record.tshortfall * 2)
+ record.errors.add :tshortfall, I18n.t("validations.financial.tshortfall.more_than_rent")
+ end
+
+ if record.tcharge.present? && weekly_value_in_range(record, "tcharge", 9.99)
+ record.errors.add :tcharge, I18n.t("validations.financial.tcharge.under_10")
+ end
+
+ answered_questions = [record.tcharge, record.chcharge].concat(record.household_charge && record.household_charge.zero? ? [record.household_charge] : [])
+ if answered_questions.count(&:present?) > 1
+ record.errors.add :tcharge, I18n.t("validations.financial.charges.complete_1_of_3") if record.tcharge.present?
+ record.errors.add :chcharge, I18n.t("validations.financial.charges.complete_1_of_3") if record.chcharge.present?
+ record.errors.add :household_charge, I18n.t("validations.financial.charges.complete_1_of_3") if record.household_charge.present?
+ end
+
+ validate_charges(record)
+ end
+
+private
+
+ CHARGE_MAXIMUMS = {
+ scharge: {
+ this_landlord: {
+ general_needs: 55,
+ supported_housing: 280,
+ },
+ other_landlord: {
+ general_needs: 45,
+ supported_housing: 165,
+ },
+ },
+ pscharge: {
+ this_landlord: {
+ general_needs: 30,
+ supported_housing: 200,
+ },
+ other_landlord: {
+ general_needs: 35,
+ supported_housing: 75,
+ },
+ },
+ supcharg: {
+ this_landlord: {
+ general_needs: 40,
+ supported_housing: 465,
+ },
+ other_landlord: {
+ general_needs: 60,
+ supported_housing: 120,
+ },
+ },
+ }.freeze
+
+ LANDLORD_VALUES = { 1 => :this_landlord, 2 => :other_landlord }.freeze
+ NEEDSTYPE_VALUES = { 0 => :supported_housing, 1 => :general_needs }.freeze
+
+ def validate_charges(record)
+ %i[scharge pscharge supcharg].each do |charge|
+ maximum = CHARGE_MAXIMUMS.dig(charge, LANDLORD_VALUES[record.landlord], NEEDSTYPE_VALUES[record.needstype])
+
+ if maximum.present? && !weekly_value_in_range(record, charge, maximum)
+ record.errors.add charge, I18n.t("validations.financial.rent.#{charge}.#{LANDLORD_VALUES[record.landlord]}.#{NEEDSTYPE_VALUES[record.needstype]}")
+ end
+ end
+ end
+
+ def weekly_value_in_range(record, field, max)
+ record[field].present? && record.weekly_value(record[field]).present? && record.weekly_value(record[field]).between?(0, max)
+ end
end
diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json
index 9c19c9cd2..8f838b8d2 100644
--- a/config/forms/2021_2022.json
+++ b/config/forms/2021_2022.json
@@ -4702,31 +4702,31 @@
"hint_text": "",
"type": "radio",
"answer_options": {
- "0": {
+ "2": {
"value": "Every 2 weeks"
},
- "1": {
+ "3": {
"value": "Every 4 weeks"
},
- "2": {
+ "4": {
"value": "Every calendar month"
},
- "3": {
+ "5": {
"value": "Weekly for 50 weeks"
},
- "4": {
+ "6": {
"value": "Weekly for 49 weeks"
},
- "5": {
+ "7": {
"value": "Weekly for 48 weeks"
},
- "6": {
+ "8": {
"value": "Weekly for 47 weeks"
},
- "7": {
+ "9": {
"value": "Weekly for 46 weeks"
},
- "8": {
+ "1": {
"value": "Weekly for 52 weeks"
}
}
@@ -4777,62 +4777,62 @@
},
"depends_on": [
{
- "period": 8,
+ "period": 1,
"needstype": 0,
"household_charge": 0
},
{
- "period": 8,
+ "period": 1,
"needstype": 0,
"household_charge": null
},
{
- "period": 3,
+ "period": 5,
"needstype": 0,
"household_charge": 0
},
{
- "period": 3,
+ "period": 5,
"needstype": 0,
"household_charge": null
},
{
- "period": 4,
+ "period": 6,
"needstype": 0,
"household_charge": 0
},
{
- "period": 4,
+ "period": 6,
"needstype": 0,
"household_charge": null
},
{
- "period": 5,
+ "period": 7,
"needstype": 0,
"household_charge": 0
},
{
- "period": 5,
+ "period": 7,
"needstype": 0,
"household_charge": null
},
{
- "period": 6,
+ "period": 8,
"needstype": 0,
"household_charge": 0
},
{
- "period": 6,
+ "period": 8,
"needstype": 0,
"household_charge": null
},
{
- "period": 7,
+ "period": 9,
"needstype": 0,
"household_charge": 0
},
{
- "period": 7,
+ "period": 9,
"needstype": 0,
"household_charge": null
}
@@ -4874,12 +4874,12 @@
},
"depends_on": [
{
- "period": 0,
+ "period": 2,
"needstype": 0,
"household_charge": 0
},
{
- "period": 0,
+ "period": 2,
"needstype": 0,
"household_charge": null
}
@@ -4921,12 +4921,12 @@
},
"depends_on": [
{
- "period": 1,
+ "period": 3,
"needstype": 0,
"household_charge": 0
},
{
- "period": 1,
+ "period": 3,
"needstype": 0,
"household_charge": null
}
@@ -4968,12 +4968,12 @@
},
"depends_on": [
{
- "period": 2,
+ "period": 4,
"needstype": 0,
"household_charge": 0
},
{
- "period": 2,
+ "period": 4,
"needstype": 0,
"household_charge": null
}
@@ -5081,122 +5081,122 @@
},
"depends_on": [
{
- "period": 8,
+ "period": 1,
"household_charge": 0,
"is_carehome": 0
},
{
- "period": 8,
+ "period": 1,
"household_charge": null,
"is_carehome": 0
},
{
- "period": 3,
+ "period": 5,
"household_charge": 0,
"is_carehome": 0
},
{
- "period": 3,
+ "period": 5,
"household_charge": null,
"is_carehome": 0
},
{
- "period": 4,
+ "period": 6,
"household_charge": 0,
"is_carehome": 0
},
{
- "period": 4,
+ "period": 6,
"household_charge": null,
"is_carehome": 0
},
{
- "period": 5,
+ "period": 7,
"household_charge": 0,
"is_carehome": 0
},
{
- "period": 5,
+ "period": 7,
"household_charge": null,
"is_carehome": 0
},
{
- "period": 6,
+ "period": 8,
"household_charge": 0,
"is_carehome": 0
},
{
- "period": 6,
+ "period": 8,
"household_charge": null,
"is_carehome": 0
},
{
- "period": 7,
+ "period": 9,
"household_charge": 0,
"is_carehome": 0
},
{
- "period": 7,
+ "period": 9,
"household_charge": null,
"is_carehome": 0
},
{
- "period": 8,
+ "period": 1,
"household_charge": 0,
"is_carehome": null
},
{
- "period": 8,
+ "period": 1,
"household_charge": null,
"is_carehome": null
},
{
- "period": 3,
+ "period": 5,
"household_charge": 0,
"is_carehome": null
},
{
- "period": 3,
+ "period": 5,
"household_charge": null,
"is_carehome": null
},
{
- "period": 4,
+ "period": 6,
"household_charge": 0,
"is_carehome": null
},
{
- "period": 4,
+ "period": 6,
"household_charge": null,
"is_carehome": null
},
{
- "period": 5,
+ "period": 7,
"household_charge": 0,
"is_carehome": null
},
{
- "period": 5,
+ "period": 7,
"household_charge": null,
"is_carehome": null
},
{
- "period": 6,
+ "period": 8,
"household_charge": 0,
"is_carehome": null
},
{
- "period": 6,
+ "period": 8,
"household_charge": null,
"is_carehome": null
},
{
- "period": 7,
+ "period": 9,
"household_charge": 0,
"is_carehome": null
},
{
- "period": 7,
+ "period": 9,
"household_charge": null,
"is_carehome": null
}
@@ -5305,22 +5305,22 @@
"depends_on": [
{
"household_charge": 0,
- "period": 0,
+ "period": 2,
"is_carehome": 0
},
{
"household_charge": null,
- "period": 0,
+ "period": 2,
"is_carehome": 0
},
{
"household_charge": 0,
- "period": 0,
+ "period": 2,
"is_carehome": null
},
{
"household_charge": null,
- "period": 0,
+ "period": 2,
"is_carehome": null
}
]
@@ -5428,22 +5428,22 @@
"depends_on": [
{
"household_charge": 0,
- "period": 1,
+ "period": 3,
"is_carehome": 0
},
{
"household_charge": null,
- "period": 1,
+ "period": 3,
"is_carehome": 0
},
{
"household_charge": 0,
- "period": 1,
+ "period": 3,
"is_carehome": null
},
{
"household_charge": null,
- "period": 1,
+ "period": 3,
"is_carehome": null
}
]
@@ -5551,22 +5551,22 @@
"depends_on": [
{
"household_charge": 0,
- "period": 2,
+ "period": 4,
"is_carehome": 0
},
{
"household_charge": null,
- "period": 2,
+ "period": 4,
"is_carehome": 0
},
{
"household_charge": 0,
- "period": 2,
+ "period": 4,
"is_carehome": null
},
{
"household_charge": null,
- "period": 2,
+ "period": 4,
"is_carehome": null
}
]
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 9095c67d6..b654ab394 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -83,7 +83,8 @@ en:
financial:
tshortfall:
- outstanding_amount_not_required: "You must not answer the outstanding amount question if you don’t have outstanding rent or charges."
+ outstanding_amount_not_required: "You must not answer the outstanding amount question if you don’t have outstanding rent or charges"
+ more_than_rent: "Answer must be less than half of the basic rent amount"
hbrentshortfall:
outstanding_no_benefits: "Outstanding amount for basic rent and/or benefit eligible charges cannot be 'Yes' if tenant is not in receipt of housing benefit or universal benefit or if benefit is unknown"
benefits:
@@ -94,6 +95,33 @@ en:
freq_missing: "Select how often the household receives income"
earnings_missing: "Enter how much income the household has in total"
negative_currency: "Enter an amount above 0"
+ rent:
+ less_than_double_shortfall: "Answer must be more than double the shortfall in basic rent"
+ scharge:
+ this_landlord:
+ general_needs: "Service charge must be between £0 and £55 per week if the landlord is this landlord and it is a general needs letting"
+ supported_housing: "Service charge must be between £0 and £280 per week if the landlord is this landlord and it is a suported housing letting"
+ other_landlord:
+ general_needs: "Service charge must be between £0 and £45 per week if the landlord is another RP and it is a general needs letting"
+ supported_housing: "Service charge must be between £0 and £165 per week if the landlord is another RP and it is a suported housing letting"
+ pscharge:
+ this_landlord:
+ general_needs: "Personal service charge must be between £0 and £30 per week if the landlord is this landlord and it is a general needs letting"
+ supported_housing: "Personal service charge must be between £0 and £200 per week if the landlord is this landlord and it is a suported housing letting"
+ other_landlord:
+ general_needs: "Personal service charge must be between £0 and £35 per week if the landlord is another RP and it is a general needs letting"
+ supported_housing: "Personal service charge must be between £0 and £75 per week if the landlord is another RP and it is a suported housing letting"
+ supcharg:
+ this_landlord:
+ general_needs: "Support charge must be between £0 and £40 per week if the landlord is this landlord and it is a general needs letting"
+ supported_housing: "Support charge must be between £0 and £465 per week if the landlord is this landlord and it is a suported housing letting"
+ other_landlord:
+ general_needs: "Support charge must be between £0 and £60 per week if the landlord is another RP and it is a general needs letting"
+ supported_housing: "Support charge must be between £0 and £120 per week if the landlord is another RP and it is a suported housing letting"
+ charges:
+ complete_1_of_3: 'Only one question out of "Total charge", "Charges for carehomes" and "Does the household pay rent or charges?" needs to be selected and completed'
+ tcharge:
+ under_10: "Total charge must be at least £10 per week"
household:
reasonpref:
diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb
index 67e6d4b32..4fffc22f0 100644
--- a/spec/factories/case_log.rb
+++ b/spec/factories/case_log.rb
@@ -68,7 +68,7 @@ FactoryBot.define do
earnings { 68 }
incfreq { 0 }
benefits { 1 }
- period { 0 }
+ period { 2 }
brent { 200 }
scharge { 50 }
pscharge { 40 }
@@ -139,10 +139,8 @@ FactoryBot.define do
armedforces { 0 }
builtype { 1 }
unitletas { 2 }
- household_charge { 1 }
has_benefits { 1 }
is_carehome { 0 }
- chcharge { 7 }
letting_in_sheltered_accommodation { 0 }
la_known { 1 }
declaration { 1 }
diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json
index 8b06563f4..14fcd404a 100644
--- a/spec/fixtures/complete_case_log.json
+++ b/spec/fixtures/complete_case_log.json
@@ -76,7 +76,7 @@
"incfreq": 0,
"benefits": 1,
"hb": 1,
- "period": 0,
+ "period": 2,
"brent": 200,
"scharge": 50,
"pscharge": 40,
@@ -141,7 +141,6 @@
"has_benefits": 1,
"household_charge": 1,
"is_carehome": 1,
- "chcharge": 6,
"letting_in_sheltered_accommodation": 0,
"declaration": 1,
"referral": 1
diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml
index 7a1b17dbd..bcb090842 100644
--- a/spec/fixtures/exports/case_logs.xml
+++ b/spec/fixtures/exports/case_logs.xml
@@ -54,7 +54,7 @@
68
0
1
- 0
+ 2
2
1
NW1 5TY
@@ -135,7 +135,7 @@
0
0
0
- 1
+
200.0
50.0
@@ -143,7 +143,7 @@
35.0
325.0
12.0
- 7.0
+
1
1
diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json
index 3c17a703e..73ff5e9ce 100644
--- a/spec/fixtures/forms/2021_2022.json
+++ b/spec/fixtures/forms/2021_2022.json
@@ -661,10 +661,10 @@
"header": "Which period are rent and other charges due?",
"type": "radio",
"answer_options": {
- "0": {
+ "2": {
"value": "Weekly for 52 weeks"
},
- "1": {
+ "3": {
"value": "Every 2 weeks"
}
}
diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb
index a441b5ae7..15b50a4e9 100644
--- a/spec/models/case_log_spec.rb
+++ b/spec/models/case_log_spec.rb
@@ -314,35 +314,35 @@ RSpec.describe CaseLog do
context "when rent is paid bi-weekly" do
it "correctly derives and saves weekly rent" do
- case_log.update!(brent: 100, period: 0)
+ case_log.update!(brent: 100, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wrent).to eq(50.0)
expect(record_from_db["wrent"]).to eq(50.0)
end
it "correctly derives and saves weekly service charge" do
- case_log.update!(scharge: 100, period: 0)
+ case_log.update!(scharge: 100, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(50.0)
expect(record_from_db["wscharge"]).to eq(50.0)
end
it "correctly derives and saves weekly personal service charge" do
- case_log.update!(pscharge: 100, period: 0)
+ case_log.update!(pscharge: 100, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(50.0)
expect(record_from_db["wpschrge"]).to eq(50.0)
end
it "correctly derives and saves weekly support charge" do
- case_log.update!(supcharg: 100, period: 0)
+ case_log.update!(supcharg: 100, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(50.0)
expect(record_from_db["wsupchrg"]).to eq(50.0)
end
it "correctly derives and saves weekly total charge" do
- case_log.update!(tcharge: 100, period: 0)
+ case_log.update!(tcharge: 100, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtcharge).to eq(50.0)
expect(record_from_db["wtcharge"]).to eq(50.0)
@@ -351,7 +351,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 100, period: 0, hb: 1)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 100, period: 2, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(50.0)
expect(record_from_db["wtshortfall"]).to eq(50.0)
@@ -360,7 +360,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 100, period: 0, hb: 6)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 100, period: 2, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(50.0)
expect(record_from_db["wtshortfall"]).to eq(50.0)
@@ -369,46 +369,61 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 100, period: 0, hb: 8)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 100, period: 2, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(50.0)
expect(record_from_db["wtshortfall"]).to eq(50.0)
end
end
end
+
+ it "correctly derives floats" do
+ case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 2)
+ record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
+ expect(case_log.wsupchrg).to eq(50.06)
+ expect(case_log.wpschrge).to eq(50.07)
+ expect(case_log.wscharge).to eq(50.49)
+ expect(case_log.wrent).to eq(50.49)
+ expect(case_log.wtcharge).to eq(201.1)
+ expect(record_from_db["wsupchrg"]).to eq(50.06)
+ expect(record_from_db["wpschrge"]).to eq(50.07)
+ expect(record_from_db["wscharge"]).to eq(50.49)
+ expect(record_from_db["wrent"]).to eq(50.49)
+ expect(record_from_db["wtcharge"]).to eq(201.1)
+ end
end
context "when rent is paid every 4 weeks" do
it "correctly derives and saves weekly rent" do
- case_log.update!(brent: 120, period: 1)
+ case_log.update!(brent: 120, period: 3)
record_from_db = ActiveRecord::Base.connection.execute("select wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wrent).to eq(30.0)
expect(record_from_db["wrent"]).to eq(30.0)
end
it "correctly derives and saves weekly service charge" do
- case_log.update!(scharge: 120, period: 1)
+ case_log.update!(scharge: 120, period: 3)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(30.0)
expect(record_from_db["wscharge"]).to eq(30.0)
end
it "correctly derives and saves weekly personal service charge" do
- case_log.update!(pscharge: 120, period: 1)
+ case_log.update!(pscharge: 120, period: 3)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(30.0)
expect(record_from_db["wpschrge"]).to eq(30.0)
end
it "correctly derives and saves weekly support charge" do
- case_log.update!(supcharg: 120, period: 1)
+ case_log.update!(supcharg: 120, period: 3)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(30.0)
expect(record_from_db["wsupchrg"]).to eq(30.0)
end
it "correctly derives and saves weekly total charge" do
- case_log.update!(tcharge: 120, period: 1)
+ case_log.update!(tcharge: 120, period: 3)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtcharge).to eq(30.0)
expect(record_from_db["wtcharge"]).to eq(30.0)
@@ -417,7 +432,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 120, period: 1, hb: 1)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 120, period: 3, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0)
@@ -426,7 +441,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 120, period: 1, hb: 6)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 120, period: 3, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0)
@@ -435,46 +450,61 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 120, period: 1, hb: 8)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 120, period: 3, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0)
end
end
end
+
+ it "correctly derives floats" do
+ case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 3)
+ record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
+ expect(case_log.wsupchrg).to eq(25.03)
+ expect(case_log.wpschrge).to eq(25.03)
+ expect(case_log.wscharge).to eq(25.24)
+ expect(case_log.wrent).to eq(25.24)
+ expect(case_log.wtcharge).to eq(100.55)
+ expect(record_from_db["wsupchrg"]).to eq(25.03)
+ expect(record_from_db["wpschrge"]).to eq(25.03)
+ expect(record_from_db["wscharge"]).to eq(25.24)
+ expect(record_from_db["wrent"]).to eq(25.24)
+ expect(record_from_db["wtcharge"]).to eq(100.55)
+ end
end
context "when rent is paid every calendar month" do
it "correctly derives and saves weekly rent" do
- case_log.update!(brent: 130, period: 2)
+ case_log.update!(brent: 130, period: 4)
record_from_db = ActiveRecord::Base.connection.execute("select wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wrent).to eq(30.0)
expect(record_from_db["wrent"]).to eq(30.0)
end
it "correctly derives and saves weekly service charge" do
- case_log.update!(scharge: 130, period: 2)
+ case_log.update!(scharge: 130, period: 4)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(30.0)
expect(record_from_db["wscharge"]).to eq(30.0)
end
it "correctly derives and saves weekly personal service charge" do
- case_log.update!(pscharge: 130, period: 2)
+ case_log.update!(pscharge: 130, period: 4)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(30.0)
expect(record_from_db["wpschrge"]).to eq(30.0)
end
it "correctly derives and saves weekly support charge" do
- case_log.update!(supcharg: 130, period: 2)
+ case_log.update!(supcharg: 130, period: 4)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(30.0)
expect(record_from_db["wsupchrg"]).to eq(30.0)
end
it "correctly derives and saves weekly total charge" do
- case_log.update!(tcharge: 130, period: 2)
+ case_log.update!(tcharge: 130, period: 4)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtcharge).to eq(30.0)
expect(record_from_db["wtcharge"]).to eq(30.0)
@@ -483,7 +513,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 2, hb: 1)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 4, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0)
@@ -492,7 +522,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 2, hb: 6)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 4, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0)
@@ -501,46 +531,61 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 2, hb: 8)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 4, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(30.0)
expect(record_from_db["wtshortfall"]).to eq(30.0)
end
end
end
+
+ it "correctly derives floats" do
+ case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 4)
+ record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
+ expect(case_log.wsupchrg).to eq(23.10)
+ expect(case_log.wpschrge).to eq(23.11)
+ expect(case_log.wscharge).to eq(23.30)
+ expect(case_log.wrent).to eq(23.30)
+ expect(case_log.wtcharge).to eq(92.82)
+ expect(record_from_db["wsupchrg"]).to eq(23.10)
+ expect(record_from_db["wpschrge"]).to eq(23.11)
+ expect(record_from_db["wscharge"]).to eq(23.30)
+ expect(record_from_db["wrent"]).to eq(23.30)
+ expect(record_from_db["wtcharge"]).to eq(92.82)
+ end
end
context "when rent is paid weekly for 50 weeks" do
it "correctly derives and saves weekly rent" do
- case_log.update!(brent: 130, period: 3)
+ case_log.update!(brent: 130, period: 5)
record_from_db = ActiveRecord::Base.connection.execute("select wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wrent).to eq(125.0)
expect(record_from_db["wrent"]).to eq(125.0)
end
it "correctly derives and saves weekly service charge" do
- case_log.update!(scharge: 130, period: 3)
+ case_log.update!(scharge: 130, period: 5)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(125.0)
expect(record_from_db["wscharge"]).to eq(125.0)
end
it "correctly derives and saves weekly personal service charge" do
- case_log.update!(pscharge: 130, period: 3)
+ case_log.update!(pscharge: 130, period: 5)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(125.0)
expect(record_from_db["wpschrge"]).to eq(125.0)
end
it "correctly derives and saves weekly support charge" do
- case_log.update!(supcharg: 130, period: 3)
+ case_log.update!(supcharg: 130, period: 5)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(125.0)
expect(record_from_db["wsupchrg"]).to eq(125.0)
end
it "correctly derives and saves weekly total charge" do
- case_log.update!(tcharge: 130, period: 3)
+ case_log.update!(tcharge: 130, period: 5)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtcharge).to eq(125.0)
expect(record_from_db["wtcharge"]).to eq(125.0)
@@ -549,7 +594,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 3, hb: 1)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 5, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(125.0)
expect(record_from_db["wtshortfall"]).to eq(125.0)
@@ -558,7 +603,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 3, hb: 6)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 5, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(125.0)
expect(record_from_db["wtshortfall"]).to eq(125.0)
@@ -567,46 +612,61 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 3, hb: 8)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 5, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(125.0)
expect(record_from_db["wtshortfall"]).to eq(125.0)
end
end
end
+
+ it "correctly derives floats" do
+ case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 5)
+ record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
+ expect(case_log.wsupchrg).to eq(96.27)
+ expect(case_log.wpschrge).to eq(96.28)
+ expect(case_log.wscharge).to eq(97.1)
+ expect(case_log.wrent).to eq(97.09)
+ expect(case_log.wtcharge).to eq(386.73)
+ expect(record_from_db["wsupchrg"]).to eq(96.27)
+ expect(record_from_db["wpschrge"]).to eq(96.28)
+ expect(record_from_db["wscharge"]).to eq(97.1)
+ expect(record_from_db["wrent"]).to eq(97.09)
+ expect(record_from_db["wtcharge"]).to eq(386.73)
+ end
end
context "when rent is paid weekly for 49 weeks" do
it "correctly derives and saves weekly rent" do
- case_log.update!(brent: 130, period: 4)
+ case_log.update!(brent: 130, period: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wrent).to eq(122.5)
expect(record_from_db["wrent"]).to eq(122.5)
end
it "correctly derives and saves weekly service charge" do
- case_log.update!(scharge: 130, period: 4)
+ case_log.update!(scharge: 130, period: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(122.5)
expect(record_from_db["wscharge"]).to eq(122.5)
end
it "correctly derives and saves weekly personal service charge" do
- case_log.update!(pscharge: 130, period: 4)
+ case_log.update!(pscharge: 130, period: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(122.5)
expect(record_from_db["wpschrge"]).to eq(122.5)
end
it "correctly derives and saves weekly support charge" do
- case_log.update!(supcharg: 130, period: 4)
+ case_log.update!(supcharg: 130, period: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(122.5)
expect(record_from_db["wsupchrg"]).to eq(122.5)
end
it "correctly derives and saves weekly total charge" do
- case_log.update!(tcharge: 130, period: 4)
+ case_log.update!(tcharge: 130, period: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtcharge).to eq(122.5)
expect(record_from_db["wtcharge"]).to eq(122.5)
@@ -615,7 +675,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 4, hb: 1)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 6, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(122.5)
expect(record_from_db["wtshortfall"]).to eq(122.5)
@@ -624,7 +684,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 4, hb: 6)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 6, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(122.5)
expect(record_from_db["wtshortfall"]).to eq(122.5)
@@ -633,46 +693,61 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 4, hb: 8)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 6, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(122.5)
expect(record_from_db["wtshortfall"]).to eq(122.5)
end
end
end
+
+ it "correctly derives floats" do
+ case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 6)
+ record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
+ expect(case_log.wsupchrg).to eq(94.34)
+ expect(case_log.wpschrge).to eq(94.35)
+ expect(case_log.wscharge).to eq(95.15)
+ expect(case_log.wrent).to eq(95.14)
+ expect(case_log.wtcharge).to eq(379)
+ expect(record_from_db["wsupchrg"]).to eq(94.34)
+ expect(record_from_db["wpschrge"]).to eq(94.35)
+ expect(record_from_db["wscharge"]).to eq(95.15)
+ expect(record_from_db["wrent"]).to eq(95.14)
+ expect(record_from_db["wtcharge"]).to eq(379)
+ end
end
context "when rent is paid weekly for 48 weeks" do
it "correctly derives and saves weekly rent" do
- case_log.update!(brent: 130, period: 5)
+ case_log.update!(brent: 130, period: 7)
record_from_db = ActiveRecord::Base.connection.execute("select wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wrent).to eq(120.0)
expect(record_from_db["wrent"]).to eq(120.0)
end
it "correctly derives and saves weekly service charge" do
- case_log.update!(scharge: 130, period: 5)
+ case_log.update!(scharge: 130, period: 7)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(120.0)
expect(record_from_db["wscharge"]).to eq(120.0)
end
it "correctly derives and saves weekly personal service charge" do
- case_log.update!(pscharge: 130, period: 5)
+ case_log.update!(pscharge: 130, period: 7)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(120.0)
expect(record_from_db["wpschrge"]).to eq(120.0)
end
it "correctly derives and saves weekly support charge" do
- case_log.update!(supcharg: 130, period: 5)
+ case_log.update!(supcharg: 130, period: 7)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(120.0)
expect(record_from_db["wsupchrg"]).to eq(120.0)
end
it "correctly derives and saves weekly total charge" do
- case_log.update!(tcharge: 130, period: 5)
+ case_log.update!(tcharge: 130, period: 7)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtcharge).to eq(120.0)
expect(record_from_db["wtcharge"]).to eq(120.0)
@@ -681,7 +756,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 5, hb: 1)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 7, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(120.0)
expect(record_from_db["wtshortfall"]).to eq(120.0)
@@ -690,7 +765,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 5, hb: 6)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 7, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(120.0)
expect(record_from_db["wtshortfall"]).to eq(120.0)
@@ -699,46 +774,61 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 5, hb: 8)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 7, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(120.0)
expect(record_from_db["wtshortfall"]).to eq(120.0)
end
end
end
+
+ it "correctly derives floats" do
+ case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 7)
+ record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
+ expect(case_log.wsupchrg).to eq(92.42)
+ expect(case_log.wpschrge).to eq(92.43)
+ expect(case_log.wscharge).to eq(93.21)
+ expect(case_log.wrent).to eq(93.20)
+ expect(case_log.wtcharge).to eq(371.26)
+ expect(record_from_db["wsupchrg"]).to eq(92.42)
+ expect(record_from_db["wpschrge"]).to eq(92.43)
+ expect(record_from_db["wscharge"]).to eq(93.21)
+ expect(record_from_db["wrent"]).to eq(93.20)
+ expect(record_from_db["wtcharge"]).to eq(371.26)
+ end
end
context "when rent is paid weekly for 47 weeks" do
it "correctly derives and saves weekly rent" do
- case_log.update!(brent: 130, period: 6)
+ case_log.update!(brent: 130, period: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wrent).to eq(117.5)
expect(record_from_db["wrent"]).to eq(117.5)
end
it "correctly derives and saves weekly service charge" do
- case_log.update!(scharge: 130, period: 6)
+ case_log.update!(scharge: 130, period: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(117.5)
expect(record_from_db["wscharge"]).to eq(117.5)
end
it "correctly derives and saves weekly personal service charge" do
- case_log.update!(pscharge: 130, period: 6)
+ case_log.update!(pscharge: 130, period: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(117.5)
expect(record_from_db["wpschrge"]).to eq(117.5)
end
it "correctly derives and saves weekly support charge" do
- case_log.update!(supcharg: 130, period: 6)
+ case_log.update!(supcharg: 130, period: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(117.5)
expect(record_from_db["wsupchrg"]).to eq(117.5)
end
it "correctly derives and saves weekly total charge" do
- case_log.update!(tcharge: 130, period: 6)
+ case_log.update!(tcharge: 130, period: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtcharge).to eq(117.5)
expect(record_from_db["wtcharge"]).to eq(117.5)
@@ -747,7 +837,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 6, hb: 1)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 8, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(117.5)
expect(record_from_db["wtshortfall"]).to eq(117.5)
@@ -756,7 +846,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 6, hb: 6)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 8, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(117.5)
expect(record_from_db["wtshortfall"]).to eq(117.5)
@@ -765,46 +855,61 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 6, hb: 8)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 8, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(117.5)
expect(record_from_db["wtshortfall"]).to eq(117.5)
end
end
end
+
+ it "correctly derives floats" do
+ case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 8)
+ record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
+ expect(case_log.wsupchrg).to eq(90.49)
+ expect(case_log.wpschrge).to eq(90.50)
+ expect(case_log.wscharge).to eq(91.27)
+ expect(case_log.wrent).to eq(91.26)
+ expect(case_log.wtcharge).to eq(363.53)
+ expect(record_from_db["wsupchrg"]).to eq(90.49)
+ expect(record_from_db["wpschrge"]).to eq(90.50)
+ expect(record_from_db["wscharge"]).to eq(91.27)
+ expect(record_from_db["wrent"]).to eq(91.26)
+ expect(record_from_db["wtcharge"]).to eq(363.53)
+ end
end
context "when rent is paid weekly for 46 weeks" do
it "correctly derives and saves weekly rent" do
- case_log.update!(brent: 130, period: 7)
+ case_log.update!(brent: 130, period: 9)
record_from_db = ActiveRecord::Base.connection.execute("select wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wrent).to eq(115.0)
expect(record_from_db["wrent"]).to eq(115.0)
end
it "correctly derives and saves weekly service charge" do
- case_log.update!(scharge: 130, period: 7)
+ case_log.update!(scharge: 130, period: 9)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(115.0)
expect(record_from_db["wscharge"]).to eq(115.0)
end
it "correctly derives and saves weekly personal service charge" do
- case_log.update!(pscharge: 130, period: 7)
+ case_log.update!(pscharge: 130, period: 9)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(115.0)
expect(record_from_db["wpschrge"]).to eq(115.0)
end
it "correctly derives and saves weekly support charge" do
- case_log.update!(supcharg: 130, period: 7)
+ case_log.update!(supcharg: 130, period: 9)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(115.0)
expect(record_from_db["wsupchrg"]).to eq(115.0)
end
it "correctly derives and saves weekly total charge" do
- case_log.update!(tcharge: 130, period: 7)
+ case_log.update!(tcharge: 130, period: 9)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtcharge).to eq(115.0)
expect(record_from_db["wtcharge"]).to eq(115.0)
@@ -813,7 +918,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 7, hb: 1)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 9, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(115.0)
expect(record_from_db["wtshortfall"]).to eq(115.0)
@@ -822,7 +927,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 7, hb: 6)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 9, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(115.0)
expect(record_from_db["wtshortfall"]).to eq(115.0)
@@ -831,46 +936,61 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 7, hb: 8)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 9, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(115.0)
expect(record_from_db["wtshortfall"]).to eq(115.0)
end
end
end
+
+ it "correctly derives floats" do
+ case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 9)
+ record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
+ expect(case_log.wsupchrg).to eq(88.57)
+ expect(case_log.wpschrge).to eq(88.58)
+ expect(case_log.wscharge).to eq(89.33)
+ expect(case_log.wrent).to eq(89.32)
+ expect(case_log.wtcharge).to eq(355.79)
+ expect(record_from_db["wsupchrg"]).to eq(88.57)
+ expect(record_from_db["wpschrge"]).to eq(88.58)
+ expect(record_from_db["wscharge"]).to eq(89.33)
+ expect(record_from_db["wrent"]).to eq(89.32)
+ expect(record_from_db["wtcharge"]).to eq(355.79)
+ end
end
context "when rent is paid weekly for 52 weeks" do
it "correctly derives and saves weekly rent" do
- case_log.update!(brent: 130, period: 8)
+ case_log.update!(brent: 130, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wrent).to eq(130.0)
expect(record_from_db["wrent"]).to eq(130.0)
end
it "correctly derives and saves weekly service charge" do
- case_log.update!(scharge: 130, period: 8)
+ case_log.update!(scharge: 130, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(130.0)
expect(record_from_db["wscharge"]).to eq(130.0)
end
it "correctly derives and saves weekly personal service charge" do
- case_log.update!(pscharge: 130, period: 8)
+ case_log.update!(pscharge: 130, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(130.0)
expect(record_from_db["wpschrge"]).to eq(130.0)
end
it "correctly derives and saves weekly support charge" do
- case_log.update!(supcharg: 130, period: 8)
+ case_log.update!(supcharg: 130, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(130.0)
expect(record_from_db["wsupchrg"]).to eq(130.0)
end
it "correctly derives and saves weekly total charge" do
- case_log.update!(tcharge: 130, period: 8)
+ case_log.update!(tcharge: 130, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtcharge).to eq(130.0)
expect(record_from_db["wtcharge"]).to eq(130.0)
@@ -879,7 +999,7 @@ RSpec.describe CaseLog do
context "when the tenant has an outstanding amount after benefits" do
context "when tenant is in receipt of housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 8, hb: 1)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 1, hb: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(130.0)
expect(record_from_db["wtshortfall"]).to eq(130.0)
@@ -888,7 +1008,7 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of universal credit with housing element exc. housing benefit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 8, hb: 6)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 1, hb: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(130.0)
expect(record_from_db["wtshortfall"]).to eq(130.0)
@@ -897,13 +1017,28 @@ RSpec.describe CaseLog do
context "when tenant is in receipt of housing benefit and universal credit" do
it "correctly derives and saves weekly total shortfall" do
- case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 8, hb: 8)
+ case_log.update!(hbrentshortfall: 0, tshortfall: 130, period: 1, hb: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtshortfall).to eq(130.0)
expect(record_from_db["wtshortfall"]).to eq(130.0)
end
end
end
+
+ it "correctly derives floats" do
+ case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 1)
+ record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
+ expect(case_log.wsupchrg).to eq(100.12)
+ expect(case_log.wpschrge).to eq(100.13)
+ expect(case_log.wscharge).to eq(100.98)
+ expect(case_log.wrent).to eq(100.97)
+ expect(case_log.wtcharge).to eq(402.2)
+ expect(record_from_db["wsupchrg"]).to eq(100.12)
+ expect(record_from_db["wpschrge"]).to eq(100.13)
+ expect(record_from_db["wscharge"]).to eq(100.98)
+ expect(record_from_db["wrent"]).to eq(100.97)
+ expect(record_from_db["wtcharge"]).to eq(402.2)
+ end
end
end
diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb
index d75df4f91..bc7128087 100644
--- a/spec/models/validations/financial_validations_spec.rb
+++ b/spec/models/validations/financial_validations_spec.rb
@@ -186,4 +186,533 @@ RSpec.describe Validations::FinancialValidations do
end
end
end
+
+ describe "rent and charges validations" do
+ context "when shortfall amount is provided" do
+ it "validates that basic rent is no less than double the shortfall" do
+ record.hbrentshortfall = 1
+ record.tshortfall = 99.50
+ record.brent = 198
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors["brent"])
+ .to include(match I18n.t("validations.financial.rent.less_than_double_shortfall", shortfall: 198))
+ expect(record.errors["tshortfall"])
+ .to include(match I18n.t("validations.financial.tshortfall.more_than_rent"))
+ end
+ end
+
+ context "when the landlord is this landlord" do
+ context "when needstype is general needs" do
+ before do
+ record.needstype = 1
+ record.landlord = 1
+ end
+
+ [{
+ period: { label: "weekly", value: 1 },
+ charge: { field: "scharge", value: 56 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "scharge", value: 300 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "scharge", value: 111 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "pscharge", value: 31 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "pscharge", value: 150 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "pscharge", value: 61 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "supcharg", value: 41 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "supcharg", value: 200 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "supcharg", value: 81 },
+ }].each do |test_case|
+ it "does not allow charges outide the range when period is #{test_case[:period][:label]}" do
+ record.period = test_case[:period][:value]
+ record[test_case[:charge][:field]] = test_case[:charge][:value]
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors[test_case[:charge][:field]])
+ .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.this_landlord.general_needs"))
+ end
+ end
+
+ [{
+ period: { label: "weekly", value: 1 },
+ charge: { field: "scharge", value: 54 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "scharge", value: 220 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "scharge", value: 109 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "pscharge", value: 30 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "pscharge", value: 120 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "pscharge", value: 59 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "supcharg", value: 39 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "supcharg", value: 120 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "supcharg", value: 79 },
+ }].each do |test_case|
+ it "does allow charges inside the range when period is #{test_case[:period][:label]}" do
+ record.period = test_case[:period][:value]
+ record[test_case[:charge][:field]] = test_case[:charge][:value]
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors[test_case[:charge][:field]])
+ .to be_empty
+ end
+ end
+ end
+
+ context "when needstype is supported housing" do
+ before do
+ record.needstype = 0
+ record.landlord = 1
+ end
+
+ [{
+ period: { label: "weekly", value: 1 },
+ charge: { field: "scharge", value: 281 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "scharge", value: 1225 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "scharge", value: 561 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "pscharge", value: 201 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "pscharge", value: 1000 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "pscharge", value: 400.80 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "supcharg", value: 466 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "supcharg", value: 3100 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "supcharg", value: 990 },
+ }].each do |test_case|
+ it "does not allow charges outide the range when period is #{test_case[:period][:label]}" do
+ record.period = test_case[:period][:value]
+ record[test_case[:charge][:field]] = test_case[:charge][:value]
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors[test_case[:charge][:field]])
+ .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.this_landlord.supported_housing"))
+ end
+ end
+
+ [{
+ period: { label: "weekly", value: 1 },
+ charge: { field: "scharge", value: 280 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "scharge", value: 1200 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "scharge", value: 559 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "pscharge", value: 199.99 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "pscharge", value: 800 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "pscharge", value: 400 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "supcharg", value: 464 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "supcharg", value: 2000 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "supcharg", value: 880 },
+ }].each do |test_case|
+ it "does allow charges inside the range when period is #{test_case[:period][:label]}" do
+ record.period = test_case[:period][:value]
+ record[test_case[:charge][:field]] = test_case[:charge][:value]
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors[test_case[:charge][:field]])
+ .to be_empty
+ end
+ end
+ end
+ end
+
+ context "when the landlord is another RP" do
+ context "when needstype is general needs" do
+ before do
+ record.needstype = 1
+ record.landlord = 2
+ end
+
+ [{
+ period: { label: "weekly", value: 1 },
+ charge: { field: "scharge", value: 46 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "scharge", value: 200 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "scharge", value: 91 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "pscharge", value: 36 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "pscharge", value: 190 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "pscharge", value: 71 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "supcharg", value: 61 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "supcharg", value: 300 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "supcharg", value: 122 },
+ }].each do |test_case|
+ it "does not allow charges outide the range when period is #{test_case[:period][:label]}" do
+ record.period = test_case[:period][:value]
+ record[test_case[:charge][:field]] = test_case[:charge][:value]
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors[test_case[:charge][:field]])
+ .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.other_landlord.general_needs"))
+ end
+ end
+
+ [{
+ period: { label: "weekly", value: 1 },
+ charge: { field: "scharge", value: 44 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "scharge", value: 160 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "scharge", value: 89 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "pscharge", value: 34 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "pscharge", value: 140 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "pscharge", value: 69 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "supcharg", value: 59.99 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "supcharg", value: 240 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "supcharg", value: 119 },
+ }].each do |test_case|
+ it "does allow charges inside the range when period is #{test_case[:period][:label]}" do
+ record.period = test_case[:period][:value]
+ record[test_case[:charge][:field]] = test_case[:charge][:value]
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors[test_case[:charge][:field]])
+ .to be_empty
+ end
+ end
+ end
+
+ context "when needstype is supported housing" do
+ before do
+ record.needstype = 0
+ record.landlord = 2
+ end
+
+ [{
+ period: { label: "weekly", value: 1 },
+ charge: { field: "scharge", value: 165.90 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "scharge", value: 750 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "scharge", value: 330.50 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "pscharge", value: 76 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "pscharge", value: 400 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "pscharge", value: 151 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "supcharg", value: 121 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "supcharg", value: 620 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "supcharg", value: 241 },
+ }].each do |test_case|
+ it "does not allow charges outide the range when period is #{test_case[:period][:label]}" do
+ record.period = test_case[:period][:value]
+ record[test_case[:charge][:field]] = test_case[:charge][:value]
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors[test_case[:charge][:field]])
+ .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.other_landlord.supported_housing"))
+ end
+ end
+
+ [{
+ period: { label: "weekly", value: 1 },
+ charge: { field: "scharge", value: 120.88 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "scharge", value: 608 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "scharge", value: 329.99 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "pscharge", value: 74 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "pscharge", value: 210 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "pscharge", value: 149 },
+ },
+ {
+ period: { label: "weekly", value: 1 },
+ charge: { field: "supcharg", value: 119 },
+ },
+ {
+ period: { label: "monthly", value: 4 },
+ charge: { field: "supcharg", value: 480 },
+ },
+ {
+ period: { label: "every 2 weeks", value: 2 },
+ charge: { field: "supcharg", value: 239 },
+ }].each do |test_case|
+ it "does allow charges inside the range when period is #{test_case[:period][:label]}" do
+ record.period = test_case[:period][:value]
+ record[test_case[:charge][:field]] = test_case[:charge][:value]
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors[test_case[:charge][:field]])
+ .to be_empty
+ end
+ end
+ end
+
+ context "when period is weekly" do
+ it "validates that total charge is at least 10 per week" do
+ record.period = 1
+ record.tcharge = 9
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors["tcharge"])
+ .to include(match I18n.t("validations.financial.tcharge.under_10"))
+ end
+
+ it "allows the total charge to be over 10 per week" do
+ record.period = 1
+ record.tcharge = 10
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors["tcharge"])
+ .to be_empty
+ end
+ end
+
+ context "when period is every 2 weeks" do
+ it "validates that total charge is at least 10 per week" do
+ record.period = 2
+ record.tcharge = 19.99
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors["tcharge"])
+ .to include(match I18n.t("validations.financial.tcharge.under_10"))
+ end
+
+ it "allows the total charge to be over 10 per week" do
+ record.period = 2
+ record.tcharge = 20
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors["tcharge"])
+ .to be_empty
+ end
+ end
+
+ context "when entering charges" do
+ it "returns an error for 3 charge types selected" do
+ record.tcharge = 19.99
+ record.chcharge = 20
+ record.household_charge = 0
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors["tcharge"])
+ .to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
+ expect(record.errors["chcharge"])
+ .to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
+ expect(record.errors["household_charge"])
+ .to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
+ end
+
+ it "returns an error for tcharge and chcharge types selected" do
+ record.tcharge = 19.99
+ record.chcharge = 20
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors["household_charge"])
+ .to be_empty
+ expect(record.errors["tcharge"])
+ .to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
+ expect(record.errors["chcharge"])
+ .to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
+ end
+
+ it "returns an error for tcharge and household_charge types selected" do
+ record.tcharge = 19.99
+ record.household_charge = 0
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors["chcharge"])
+ .to be_empty
+ expect(record.errors["tcharge"])
+ .to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
+ expect(record.errors["household_charge"])
+ .to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
+ end
+
+ it "returns an error for chcharge and household_charge types selected" do
+ record.chcharge = 20
+ record.household_charge = 0
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors["tcharge"])
+ .to be_empty
+ expect(record.errors["chcharge"])
+ .to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
+ expect(record.errors["household_charge"])
+ .to include(match I18n.t("validations.financial.charges.complete_1_of_3"))
+ end
+ end
+
+ it "does not return an error for household_charge being yes" do
+ record.household_charge = 0
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors["tcharge"])
+ .to be_empty
+ expect(record.errors["chcharge"])
+ .to be_empty
+ expect(record.errors["household_charge"])
+ .to be_empty
+ end
+
+ it "does not return an error for chcharge being selected" do
+ record.household_charge = 1
+ record.chcharge = 20
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors["tcharge"])
+ .to be_empty
+ expect(record.errors["chcharge"])
+ .to be_empty
+ expect(record.errors["household_charge"])
+ .to be_empty
+ end
+
+ it "does not return an error for tcharge being selected" do
+ record.household_charge = 1
+ record.tcharge = 19.99
+ financial_validator.validate_rent_amount(record)
+ expect(record.errors["tcharge"])
+ .to be_empty
+ expect(record.errors["chcharge"])
+ .to be_empty
+ expect(record.errors["household_charge"])
+ .to be_empty
+ end
+ end
+ end
end
diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb
index 5d9611620..9819c3d49 100644
--- a/spec/models/validations/household_validations_spec.rb
+++ b/spec/models/validations/household_validations_spec.rb
@@ -6,62 +6,6 @@ RSpec.describe Validations::HouseholdValidations do
let(:validator_class) { Class.new { include Validations::HouseholdValidations } }
let(:record) { FactoryBot.create(:case_log) }
- describe "age validations" do
- it "validates that person 1's age is a number" do
- record.age1 = "random"
- household_validator.validate_numeric_min_max(record)
- expect(record.errors["age1"])
- .to include(match I18n.t("validations.numeric.valid", field: "Lead tenant’s age", min: 16, max: 120))
- end
-
- it "validates that other household member ages are a number" do
- record.age2 = "random"
- household_validator.validate_numeric_min_max(record)
- expect(record.errors["age2"])
- .to include(match I18n.t("validations.numeric.valid", field: "Person 2’s age", min: 1, max: 120))
- end
-
- it "validates that person 1's age is greater than 16" do
- record.age1 = 15
- household_validator.validate_numeric_min_max(record)
- expect(record.errors["age1"])
- .to include(match I18n.t("validations.numeric.valid", field: "Lead tenant’s age", min: 16, max: 120))
- end
-
- it "validates that other household member ages are greater than 1" do
- record.age2 = 0
- household_validator.validate_numeric_min_max(record)
- expect(record.errors["age2"])
- .to include(match I18n.t("validations.numeric.valid", field: "Person 2’s age", min: 1, max: 120))
- end
-
- it "validates that person 1's age is less than 121" do
- record.age1 = 121
- household_validator.validate_numeric_min_max(record)
- expect(record.errors["age1"])
- .to include(match I18n.t("validations.numeric.valid", field: "Lead tenant’s age", min: 16, max: 120))
- end
-
- it "validates that other household member ages are greater than 121" do
- record.age2 = 123
- household_validator.validate_numeric_min_max(record)
- expect(record.errors["age2"])
- .to include(match I18n.t("validations.numeric.valid", field: "Person 2’s age", min: 1, max: 120))
- end
-
- it "validates that person 1's age is between 16 and 120" do
- record.age1 = 63
- household_validator.validate_numeric_min_max(record)
- expect(record.errors["age1"]).to be_empty
- end
-
- it "validates that other household member ages are between 1 and 120" do
- record.age6 = 45
- household_validator.validate_numeric_min_max(record)
- expect(record.errors["age6"]).to be_empty
- end
- end
-
describe "reasonable preference validations" do
context "when reasonable preference is homeless" do
context "when the tenant was not previously homeless" do
diff --git a/spec/models/validations/shared_validations_spec.rb b/spec/models/validations/shared_validations_spec.rb
new file mode 100644
index 000000000..043f3d057
--- /dev/null
+++ b/spec/models/validations/shared_validations_spec.rb
@@ -0,0 +1,66 @@
+require "rails_helper"
+
+RSpec.describe Validations::SharedValidations do
+ subject(:household_validator) { validator_class.new }
+
+ let(:validator_class) { Class.new { include Validations::SharedValidations } }
+ let(:record) { FactoryBot.create(:case_log) }
+
+ describe "numeric min max validations" do
+ context "when validating age" do
+ it "validates that person 1's age is a number" do
+ record.age1 = "random"
+ household_validator.validate_numeric_min_max(record)
+ expect(record.errors["age1"])
+ .to include(match I18n.t("validations.numeric.valid", field: "Lead tenant’s age", min: 16, max: 120))
+ end
+
+ it "validates that other household member ages are a number" do
+ record.age2 = "random"
+ household_validator.validate_numeric_min_max(record)
+ expect(record.errors["age2"])
+ .to include(match I18n.t("validations.numeric.valid", field: "Person 2’s age", min: 1, max: 120))
+ end
+
+ it "validates that person 1's age is greater than 16" do
+ record.age1 = 15
+ household_validator.validate_numeric_min_max(record)
+ expect(record.errors["age1"])
+ .to include(match I18n.t("validations.numeric.valid", field: "Lead tenant’s age", min: 16, max: 120))
+ end
+
+ it "validates that other household member ages are greater than 1" do
+ record.age2 = 0
+ household_validator.validate_numeric_min_max(record)
+ expect(record.errors["age2"])
+ .to include(match I18n.t("validations.numeric.valid", field: "Person 2’s age", min: 1, max: 120))
+ end
+
+ it "validates that person 1's age is less than 121" do
+ record.age1 = 121
+ household_validator.validate_numeric_min_max(record)
+ expect(record.errors["age1"])
+ .to include(match I18n.t("validations.numeric.valid", field: "Lead tenant’s age", min: 16, max: 120))
+ end
+
+ it "validates that other household member ages are greater than 121" do
+ record.age2 = 123
+ household_validator.validate_numeric_min_max(record)
+ expect(record.errors["age2"])
+ .to include(match I18n.t("validations.numeric.valid", field: "Person 2’s age", min: 1, max: 120))
+ end
+
+ it "validates that person 1's age is between 16 and 120" do
+ record.age1 = 63
+ household_validator.validate_numeric_min_max(record)
+ expect(record.errors["age1"]).to be_empty
+ end
+
+ it "validates that other household member ages are between 1 and 120" do
+ record.age6 = 45
+ household_validator.validate_numeric_min_max(record)
+ expect(record.errors["age6"]).to be_empty
+ end
+ end
+ end
+end