You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2389 lines
112 KiB
2389 lines
112 KiB
3 years ago
|
require "rails_helper"
|
||
|
|
||
2 years ago
|
RSpec.describe LettingsLog do
|
||
3 years ago
|
let(:owning_organisation) { FactoryBot.create(:organisation) }
|
||
3 years ago
|
let(:different_managing_organisation) { FactoryBot.create(:organisation) }
|
||
3 years ago
|
let(:created_by_user) { FactoryBot.create(:user) }
|
||
3 years ago
|
|
||
3 years ago
|
describe "#form" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.build(:lettings_log, created_by: created_by_user) }
|
||
|
let(:lettings_log_2) { FactoryBot.build(:lettings_log, startdate: Time.zone.local(2022, 1, 1), created_by: created_by_user) }
|
||
|
let(:lettings_log_year_2) { FactoryBot.build(:lettings_log, startdate: Time.zone.local(2023, 5, 1), created_by: created_by_user) }
|
||
3 years ago
|
|
||
3 years ago
|
it "has returns the correct form based on the start date" do
|
||
2 years ago
|
expect(lettings_log.form_name).to be_nil
|
||
|
expect(lettings_log.form).to be_a(Form)
|
||
|
expect(lettings_log_2.form_name).to eq("2021_2022")
|
||
|
expect(lettings_log_2.form).to be_a(Form)
|
||
|
expect(lettings_log_year_2.form_name).to eq("2023_2024")
|
||
|
expect(lettings_log_year_2.form).to be_a(Form)
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when a date outside the collection window is passed" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.build(:lettings_log, startdate: Time.zone.local(2015, 1, 1), created_by: created_by_user) }
|
||
3 years ago
|
|
||
|
it "returns the first form" do
|
||
2 years ago
|
expect(lettings_log.form).to be_a(Form)
|
||
|
expect(lettings_log.form.start_date.year).to eq(2021)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
end
|
||
|
|
||
3 years ago
|
describe "#new" do
|
||
3 years ago
|
context "when creating a record" do
|
||
2 years ago
|
let(:lettings_log) do
|
||
3 years ago
|
described_class.create(
|
||
3 years ago
|
owning_organisation:,
|
||
3 years ago
|
managing_organisation: owning_organisation,
|
||
3 years ago
|
created_by: created_by_user,
|
||
3 years ago
|
)
|
||
3 years ago
|
end
|
||
|
|
||
3 years ago
|
it "attaches the correct custom validator" do
|
||
2 years ago
|
expect(lettings_log._validators.values.flatten.map(&:class))
|
||
|
.to include(LettingsLogValidator)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
describe "#update" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, created_by: created_by_user) }
|
||
|
let(:validator) { lettings_log._validators[nil].first }
|
||
3 years ago
|
|
||
|
after do
|
||
2 years ago
|
lettings_log.update(age1: 25)
|
||
3 years ago
|
end
|
||
|
|
||
3 years ago
|
it "validates start date" do
|
||
|
expect(validator).to receive(:validate_startdate)
|
||
|
end
|
||
|
|
||
3 years ago
|
it "validates intermediate rent product name" do
|
||
3 years ago
|
expect(validator).to receive(:validate_irproduct_other)
|
||
3 years ago
|
end
|
||
|
|
||
3 years ago
|
it "validates other household member details" do
|
||
3 years ago
|
expect(validator).to receive(:validate_household_number_of_other_members)
|
||
|
end
|
||
|
|
||
|
it "validates bedroom number" do
|
||
|
expect(validator).to receive(:validate_shared_housing_rooms)
|
||
|
end
|
||
|
|
||
|
it "validates number of times the property has been relet" do
|
||
|
expect(validator).to receive(:validate_property_number_of_times_relet)
|
||
|
end
|
||
|
|
||
3 years ago
|
it "validates tenancy type" do
|
||
3 years ago
|
expect(validator).to receive(:validate_fixed_term_tenancy)
|
||
3 years ago
|
expect(validator).to receive(:validate_other_tenancy_type)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "validates the previous postcode" do
|
||
|
expect(validator).to receive(:validate_previous_accommodation_postcode)
|
||
|
end
|
||
|
|
||
|
it "validates the net income" do
|
||
|
expect(validator).to receive(:validate_net_income)
|
||
|
end
|
||
|
|
||
|
it "validates reasonable preference" do
|
||
|
expect(validator).to receive(:validate_reasonable_preference)
|
||
|
end
|
||
3 years ago
|
|
||
|
it "validates reason for leaving last settled home" do
|
||
|
expect(validator).to receive(:validate_reason_for_leaving_last_settled_home)
|
||
|
end
|
||
|
|
||
3 years ago
|
it "validates previous housing situation" do
|
||
|
expect(validator).to receive(:validate_previous_housing_situation)
|
||
|
end
|
||
|
|
||
3 years ago
|
it "validates the min and max of numeric questions" do
|
||
|
expect(validator).to receive(:validate_numeric_min_max)
|
||
|
end
|
||
|
|
||
3 years ago
|
it "validates armed forces" do
|
||
|
expect(validator).to receive(:validate_armed_forces)
|
||
|
end
|
||
|
|
||
|
it "validates property major repairs date" do
|
||
|
expect(validator).to receive(:validate_property_major_repairs)
|
||
|
end
|
||
|
|
||
|
it "validates property void date" do
|
||
|
expect(validator).to receive(:validate_property_void_date)
|
||
|
end
|
||
3 years ago
|
|
||
|
it "validates benefits as proportion of income" do
|
||
|
expect(validator).to receive(:validate_net_income_uc_proportion)
|
||
|
end
|
||
|
|
||
|
it "validates outstanding rent amount" do
|
||
|
expect(validator).to receive(:validate_outstanding_rent_amount)
|
||
|
end
|
||
|
|
||
3 years ago
|
it "validates the rent period" do
|
||
|
expect(validator).to receive(:validate_rent_period)
|
||
|
end
|
||
|
|
||
3 years ago
|
it "validates housing benefit rent shortfall" do
|
||
|
expect(validator).to receive(:validate_tshortfall)
|
||
|
end
|
||
|
|
||
|
it "validates let type" do
|
||
|
expect(validator).to receive(:validate_unitletas)
|
||
|
end
|
||
|
|
||
|
it "validates reason for vacancy" do
|
||
|
expect(validator).to receive(:validate_rsnvac)
|
||
|
end
|
||
3 years ago
|
|
||
3 years ago
|
it "validates referral" do
|
||
|
expect(validator).to receive(:validate_referral)
|
||
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
describe "status" do
|
||
2 years ago
|
let!(:empty_lettings_log) { FactoryBot.create(:lettings_log) }
|
||
|
let!(:in_progress_lettings_log) { FactoryBot.create(:lettings_log, :in_progress) }
|
||
|
let!(:completed_lettings_log) { FactoryBot.create(:lettings_log, :completed) }
|
||
3 years ago
|
|
||
2 years ago
|
it "is set to not started for an empty lettings log" do
|
||
|
expect(empty_lettings_log.not_started?).to be(true)
|
||
|
expect(empty_lettings_log.in_progress?).to be(false)
|
||
|
expect(empty_lettings_log.completed?).to be(false)
|
||
3 years ago
|
end
|
||
|
|
||
2 years ago
|
it "is set to in progress for a started lettings log" do
|
||
|
expect(in_progress_lettings_log.in_progress?).to be(true)
|
||
|
expect(in_progress_lettings_log.not_started?).to be(false)
|
||
|
expect(in_progress_lettings_log.completed?).to be(false)
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
2 years ago
|
it "is set to completed for a completed lettings log" do
|
||
|
expect(completed_lettings_log.in_progress?).to be(false)
|
||
|
expect(completed_lettings_log.not_started?).to be(false)
|
||
|
expect(completed_lettings_log.completed?).to be(true)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
describe "weekly_net_income" do
|
||
|
let(:net_income) { 5000 }
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.build(:lettings_log, earnings: net_income) }
|
||
3 years ago
|
|
||
|
it "returns input income if frequency is already weekly" do
|
||
2 years ago
|
lettings_log.incfreq = 1
|
||
|
expect(lettings_log.weekly_net_income).to eq(net_income)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "calculates the correct weekly income from monthly income" do
|
||
2 years ago
|
lettings_log.incfreq = 2
|
||
|
expect(lettings_log.weekly_net_income).to eq(1154)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "calculates the correct weekly income from yearly income" do
|
||
2 years ago
|
lettings_log.incfreq = 3
|
||
|
expect(lettings_log.weekly_net_income).to eq(96)
|
||
3 years ago
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
describe "derived variables" do
|
||
2 years ago
|
let!(:lettings_log) do
|
||
3 years ago
|
described_class.create({
|
||
3 years ago
|
managing_organisation: owning_organisation,
|
||
|
owning_organisation:,
|
||
3 years ago
|
created_by: created_by_user,
|
||
3 years ago
|
postcode_full: "M1 1AE",
|
||
|
ppostcode_full: "M2 2AE",
|
||
3 years ago
|
startdate: Time.gm(2021, 10, 10),
|
||
|
mrcdate: Time.gm(2021, 5, 4),
|
||
3 years ago
|
voiddate: Time.gm(2021, 3, 3),
|
||
3 years ago
|
net_income_known: 2,
|
||
3 years ago
|
hhmemb: 7,
|
||
3 years ago
|
rent_type: 4,
|
||
3 years ago
|
hb: 1,
|
||
3 years ago
|
hbrentshortfall: 1,
|
||
3 years ago
|
})
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves partial and full major repairs date" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select mrcdate from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["mrcdate"].day).to eq(4)
|
||
|
expect(record_from_db["mrcdate"].month).to eq(5)
|
||
|
expect(record_from_db["mrcdate"].year).to eq(2021)
|
||
|
end
|
||
|
|
||
3 years ago
|
it "correctly derives and saves partial and full major property void date" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select voiddate from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["voiddate"].day).to eq(3)
|
||
|
expect(record_from_db["voiddate"].month).to eq(3)
|
||
|
expect(record_from_db["voiddate"].year).to eq(2021)
|
||
3 years ago
|
end
|
||
|
|
||
3 years ago
|
it "correctly derives and saves incref" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select incref from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["incref"]).to eq(1)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves renttype" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select renttype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.renttype).to eq(3)
|
||
3 years ago
|
expect(record_from_db["renttype"]).to eq(3)
|
||
|
end
|
||
3 years ago
|
|
||
3 years ago
|
context "when deriving lettype" do
|
||
|
context "when the owning organisation is a PRP" do
|
||
2 years ago
|
before { lettings_log.owning_organisation.update!(provider_type: 2) }
|
||
3 years ago
|
|
||
3 years ago
|
context "when the rent type is intermediate rent and supported housing" do
|
||
|
it "correctly derives and saves lettype" do
|
||
2 years ago
|
lettings_log.update!(rent_type: 4, needstype: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select lettype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.lettype).to eq(10)
|
||
3 years ago
|
expect(record_from_db["lettype"]).to eq(10)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the rent type is intermediate rent and general needs housing" do
|
||
|
it "correctly derives and saves lettype" do
|
||
2 years ago
|
lettings_log.update!(rent_type: 4, needstype: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select lettype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.lettype).to eq(9)
|
||
3 years ago
|
expect(record_from_db["lettype"]).to eq(9)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the rent type is affordable rent and supported housing" do
|
||
|
it "correctly derives and saves lettype" do
|
||
2 years ago
|
lettings_log.update!(rent_type: 2, needstype: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select lettype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.lettype).to eq(6)
|
||
3 years ago
|
expect(record_from_db["lettype"]).to eq(6)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the rent type is affordable rent and general needs housing" do
|
||
|
it "correctly derives and saves lettype" do
|
||
2 years ago
|
lettings_log.update!(rent_type: 2, needstype: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select lettype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.lettype).to eq(5)
|
||
3 years ago
|
expect(record_from_db["lettype"]).to eq(5)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the rent type is social rent and supported housing" do
|
||
|
it "correctly derives and saves lettype" do
|
||
2 years ago
|
lettings_log.update!(rent_type: 0, needstype: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select lettype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.lettype).to eq(2)
|
||
3 years ago
|
expect(record_from_db["lettype"]).to eq(2)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the rent type is social rent and general needs housing" do
|
||
|
it "correctly derives and saves lettype" do
|
||
2 years ago
|
lettings_log.update!(rent_type: 0, needstype: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select lettype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.lettype).to eq(1)
|
||
3 years ago
|
expect(record_from_db["lettype"]).to eq(1)
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
3 years ago
|
context "when the tenant is not in receipt of applicable benefits" do
|
||
|
it "correctly resets total shortfall" do
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 2, wtshortfall: 100, hb: 9)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to be_nil
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to be_nil
|
||
|
end
|
||
|
end
|
||
|
|
||
3 years ago
|
context "when rent is paid bi-weekly" do
|
||
|
it "correctly derives and saves weekly rent" do
|
||
2 years ago
|
lettings_log.update!(brent: 100, period: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wrent).to eq(50.0)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(50.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly service charge" do
|
||
2 years ago
|
lettings_log.update!(scharge: 70, period: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wscharge).to eq(35.0)
|
||
3 years ago
|
expect(record_from_db["wscharge"]).to eq(35.0)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly personal service charge" do
|
||
2 years ago
|
lettings_log.update!(pscharge: 60, period: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wpschrge).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wpschrge"]).to eq(30.0)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly support charge" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 80, period: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(40.0)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(40.0)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly total charge" do
|
||
2 years ago
|
lettings_log.update!(tcharge: 100, period: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtcharge).to eq(50.0)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(50.0)
|
||
|
end
|
||
3 years ago
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 100, period: 2, hb: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(50.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(50.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 100, period: 2, hb: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(50.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(50.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when tenant is in receipt of housing benefit and universal credit" do
|
||
|
it "correctly derives and saves weekly total shortfall" do
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 100, period: 2, hb: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(50.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(50.0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 60.12, pscharge: 50.13, scharge: 60.98, brent: 60.97, period: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(30.06)
|
||
|
expect(lettings_log.wpschrge).to eq(25.06)
|
||
|
expect(lettings_log.wscharge).to eq(30.49)
|
||
|
expect(lettings_log.wrent).to eq(30.49)
|
||
|
expect(lettings_log.wtcharge).to eq(116.1)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(30.06)
|
||
3 years ago
|
expect(record_from_db["wpschrge"]).to eq(25.06)
|
||
3 years ago
|
expect(record_from_db["wscharge"]).to eq(30.49)
|
||
|
expect(record_from_db["wrent"]).to eq(30.49)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(116.1)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when rent is paid every 4 weeks" do
|
||
|
it "correctly derives and saves weekly rent" do
|
||
2 years ago
|
lettings_log.update!(brent: 120, period: 3)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wrent).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(30.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly service charge" do
|
||
2 years ago
|
lettings_log.update!(scharge: 120, period: 3)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wscharge).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wscharge"]).to eq(30.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly personal service charge" do
|
||
2 years ago
|
lettings_log.update!(pscharge: 120, period: 3)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wpschrge).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wpschrge"]).to eq(30.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly support charge" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 120, period: 3)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(30.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly total charge" do
|
||
2 years ago
|
lettings_log.update!(tcharge: 120, period: 3)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtcharge).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(30.0)
|
||
|
end
|
||
3 years ago
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 120, period: 3, hb: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(30.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 120, period: 3, hb: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(30.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when tenant is in receipt of housing benefit and universal credit" do
|
||
|
it "correctly derives and saves weekly total shortfall" do
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 120, period: 3, hb: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(30.0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_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 lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(25.03)
|
||
|
expect(lettings_log.wpschrge).to eq(25.03)
|
||
|
expect(lettings_log.wscharge).to eq(25.24)
|
||
|
expect(lettings_log.wrent).to eq(25.24)
|
||
|
expect(lettings_log.wtcharge).to eq(100.55)
|
||
3 years ago
|
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
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when rent is paid every calendar month" do
|
||
|
it "correctly derives and saves weekly rent" do
|
||
2 years ago
|
lettings_log.update!(brent: 130, period: 4)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wrent).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(30.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly service charge" do
|
||
2 years ago
|
lettings_log.update!(scharge: 130, period: 4)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wscharge).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wscharge"]).to eq(30.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly personal service charge" do
|
||
2 years ago
|
lettings_log.update!(pscharge: 130, period: 4)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wpschrge).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wpschrge"]).to eq(30.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly support charge" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 130, period: 4)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(30.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly total charge" do
|
||
2 years ago
|
lettings_log.update!(tcharge: 130, period: 4)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtcharge).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(30.0)
|
||
|
end
|
||
3 years ago
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 4, hb: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(30.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 4, hb: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(30.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when tenant is in receipt of housing benefit and universal credit" do
|
||
|
it "correctly derives and saves weekly total shortfall" do
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 4, hb: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(30.0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_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 lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(23.10)
|
||
|
expect(lettings_log.wpschrge).to eq(23.11)
|
||
|
expect(lettings_log.wscharge).to eq(23.30)
|
||
|
expect(lettings_log.wrent).to eq(23.30)
|
||
|
expect(lettings_log.wtcharge).to eq(92.82)
|
||
3 years ago
|
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
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when rent is paid weekly for 50 weeks" do
|
||
|
it "correctly derives and saves weekly rent" do
|
||
2 years ago
|
lettings_log.update!(brent: 130, period: 5)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wrent).to eq(125.0)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(125.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly service charge" do
|
||
2 years ago
|
lettings_log.update!(scharge: 20, period: 5)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wscharge).to eq(19.23)
|
||
3 years ago
|
expect(record_from_db["wscharge"]).to eq(19.23)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly personal service charge" do
|
||
2 years ago
|
lettings_log.update!(pscharge: 20, period: 5)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wpschrge).to eq(19.23)
|
||
3 years ago
|
expect(record_from_db["wpschrge"]).to eq(19.23)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly support charge" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 20, period: 5)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(19.23)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(19.23)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly total charge" do
|
||
2 years ago
|
lettings_log.update!(tcharge: 130, period: 5)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtcharge).to eq(125.0)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(125.0)
|
||
|
end
|
||
3 years ago
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 5, hb: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(125.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(125.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 5, hb: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(125.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(125.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when tenant is in receipt of housing benefit and universal credit" do
|
||
|
it "correctly derives and saves weekly total shortfall" do
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 5, hb: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(125.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(125.0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 20.12, pscharge: 20.13, scharge: 20.98, brent: 100.97, period: 5)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(19.35)
|
||
|
expect(lettings_log.wpschrge).to eq(19.36)
|
||
|
expect(lettings_log.wscharge).to eq(20.17)
|
||
|
expect(lettings_log.wrent).to eq(97.09)
|
||
|
expect(lettings_log.wtcharge).to eq(155.96)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(19.35)
|
||
|
expect(record_from_db["wpschrge"]).to eq(19.36)
|
||
|
expect(record_from_db["wscharge"]).to eq(20.17)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(97.09)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(155.96)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when rent is paid weekly for 49 weeks" do
|
||
|
it "correctly derives and saves weekly rent" do
|
||
2 years ago
|
lettings_log.update!(brent: 130, period: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wrent).to eq(122.5)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(122.5)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly service charge" do
|
||
2 years ago
|
lettings_log.update!(scharge: 30, period: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wscharge).to eq(28.27)
|
||
3 years ago
|
expect(record_from_db["wscharge"]).to eq(28.27)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly personal service charge" do
|
||
2 years ago
|
lettings_log.update!(pscharge: 30, period: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wpschrge).to eq(28.27)
|
||
3 years ago
|
expect(record_from_db["wpschrge"]).to eq(28.27)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly support charge" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 30, period: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(28.27)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(28.27)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly total charge" do
|
||
2 years ago
|
lettings_log.update!(tcharge: 130, period: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtcharge).to eq(122.5)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(122.5)
|
||
|
end
|
||
3 years ago
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 6, hb: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(122.5)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(122.5)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 6, hb: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(122.5)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(122.5)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when tenant is in receipt of housing benefit and universal credit" do
|
||
|
it "correctly derives and saves weekly total shortfall" do
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 6, hb: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(122.5)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(122.5)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 30.12, pscharge: 30.13, scharge: 30.98, brent: 100.97, period: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(28.38)
|
||
|
expect(lettings_log.wpschrge).to eq(28.39)
|
||
|
expect(lettings_log.wscharge).to eq(29.19)
|
||
|
expect(lettings_log.wrent).to eq(95.14)
|
||
|
expect(lettings_log.wtcharge).to eq(181.11)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(28.38)
|
||
|
expect(record_from_db["wpschrge"]).to eq(28.39)
|
||
|
expect(record_from_db["wscharge"]).to eq(29.19)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(95.14)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(181.11)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when rent is paid weekly for 48 weeks" do
|
||
|
it "correctly derives and saves weekly rent" do
|
||
2 years ago
|
lettings_log.update!(brent: 130, period: 7)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wrent).to eq(120.0)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(120.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly service charge" do
|
||
2 years ago
|
lettings_log.update!(scharge: 30, period: 7)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wscharge).to eq(27.69)
|
||
3 years ago
|
expect(record_from_db["wscharge"]).to eq(27.69)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly personal service charge" do
|
||
2 years ago
|
lettings_log.update!(pscharge: 30, period: 7)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wpschrge).to eq(27.69)
|
||
3 years ago
|
expect(record_from_db["wpschrge"]).to eq(27.69)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly support charge" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 30, period: 7)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(27.69)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(27.69)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly total charge" do
|
||
2 years ago
|
lettings_log.update!(tcharge: 130, period: 7)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtcharge).to eq(120.0)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(120.0)
|
||
|
end
|
||
3 years ago
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 7, hb: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(120.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(120.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 7, hb: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(120.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(120.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when tenant is in receipt of housing benefit and universal credit" do
|
||
|
it "correctly derives and saves weekly total shortfall" do
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 7, hb: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(120.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(120.0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 30.12, pscharge: 30.13, scharge: 30.98, brent: 100.97, period: 7)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(27.8)
|
||
|
expect(lettings_log.wpschrge).to eq(27.81)
|
||
|
expect(lettings_log.wscharge).to eq(28.6)
|
||
|
expect(lettings_log.wrent).to eq(93.20)
|
||
|
expect(lettings_log.wtcharge).to eq(177.42)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(27.8)
|
||
|
expect(record_from_db["wpschrge"]).to eq(27.81)
|
||
|
expect(record_from_db["wscharge"]).to eq(28.6)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(93.20)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(177.42)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when rent is paid weekly for 47 weeks" do
|
||
|
it "correctly derives and saves weekly rent" do
|
||
2 years ago
|
lettings_log.update!(brent: 130, period: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wrent).to eq(117.5)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(117.5)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly service charge" do
|
||
2 years ago
|
lettings_log.update!(scharge: 30, period: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wscharge).to eq(27.12)
|
||
3 years ago
|
expect(record_from_db["wscharge"]).to eq(27.12)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly personal service charge" do
|
||
2 years ago
|
lettings_log.update!(pscharge: 30, period: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wpschrge).to eq(27.12)
|
||
3 years ago
|
expect(record_from_db["wpschrge"]).to eq(27.12)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly support charge" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 30, period: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(27.12)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(27.12)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly total charge" do
|
||
2 years ago
|
lettings_log.update!(tcharge: 130, period: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtcharge).to eq(117.5)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(117.5)
|
||
|
end
|
||
3 years ago
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 8, hb: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(117.5)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(117.5)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 8, hb: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(117.5)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(117.5)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when tenant is in receipt of housing benefit and universal credit" do
|
||
|
it "correctly derives and saves weekly total shortfall" do
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 8, hb: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(117.5)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(117.5)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 30.12, pscharge: 30.13, scharge: 30.98, brent: 100.97, period: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(27.22)
|
||
|
expect(lettings_log.wpschrge).to eq(27.23)
|
||
|
expect(lettings_log.wscharge).to eq(28)
|
||
|
expect(lettings_log.wrent).to eq(91.26)
|
||
|
expect(lettings_log.wtcharge).to eq(173.72)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(27.22)
|
||
|
expect(record_from_db["wpschrge"]).to eq(27.23)
|
||
|
expect(record_from_db["wscharge"]).to eq(28)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(91.26)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(173.72)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when rent is paid weekly for 46 weeks" do
|
||
|
it "correctly derives and saves weekly rent" do
|
||
2 years ago
|
lettings_log.update!(brent: 130, period: 9)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wrent).to eq(115.0)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(115.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly service charge" do
|
||
2 years ago
|
lettings_log.update!(scharge: 30, period: 9)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wscharge).to eq(26.54)
|
||
3 years ago
|
expect(record_from_db["wscharge"]).to eq(26.54)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly personal service charge" do
|
||
2 years ago
|
lettings_log.update!(pscharge: 30, period: 9)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wpschrge).to eq(26.54)
|
||
3 years ago
|
expect(record_from_db["wpschrge"]).to eq(26.54)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly support charge" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 30, period: 9)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(26.54)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(26.54)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly total charge" do
|
||
2 years ago
|
lettings_log.update!(tcharge: 130, period: 9)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtcharge).to eq(115.0)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(115.0)
|
||
|
end
|
||
3 years ago
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 9, hb: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(115.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(115.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 9, hb: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(115.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(115.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when tenant is in receipt of housing benefit and universal credit" do
|
||
|
it "correctly derives and saves weekly total shortfall" do
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 9, hb: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(115.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(115.0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 30.12, pscharge: 30.13, scharge: 30.98, brent: 100.97, period: 9)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(26.64)
|
||
|
expect(lettings_log.wpschrge).to eq(26.65)
|
||
|
expect(lettings_log.wscharge).to eq(27.41)
|
||
|
expect(lettings_log.wrent).to eq(89.32)
|
||
|
expect(lettings_log.wtcharge).to eq(170.02)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(26.64)
|
||
|
expect(record_from_db["wpschrge"]).to eq(26.65)
|
||
|
expect(record_from_db["wscharge"]).to eq(27.41)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(89.32)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(170.02)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when rent is paid weekly for 52 weeks" do
|
||
|
it "correctly derives and saves weekly rent" do
|
||
2 years ago
|
lettings_log.update!(brent: 130, period: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wrent).to eq(130.0)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(130.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly service charge" do
|
||
2 years ago
|
lettings_log.update!(scharge: 30, period: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wscharge).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wscharge"]).to eq(30.0)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly personal service charge" do
|
||
2 years ago
|
lettings_log.update!(pscharge: 30, period: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wpschrge).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wpschrge"]).to eq(30.0)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly support charge" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 30, period: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(30.0)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves weekly total charge" do
|
||
2 years ago
|
lettings_log.update!(tcharge: 30, period: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtcharge).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(30.0)
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 1, hb: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(130.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(130.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
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
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 1, hb: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(130.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(130.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when tenant is in receipt of housing benefit and universal credit" do
|
||
|
it "correctly derives and saves weekly total shortfall" do
|
||
2 years ago
|
lettings_log.update!(hbrentshortfall: 1, tshortfall: 130, period: 1, hb: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtshortfall from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wtshortfall).to eq(130.0)
|
||
3 years ago
|
expect(record_from_db["wtshortfall"]).to eq(130.0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(supcharg: 30.12, pscharge: 25.13, scharge: 30.98, brent: 100.97, period: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wsupchrg).to eq(30.12)
|
||
|
expect(lettings_log.wpschrge).to eq(25.13)
|
||
|
expect(lettings_log.wscharge).to eq(30.98)
|
||
|
expect(lettings_log.wrent).to eq(100.97)
|
||
|
expect(lettings_log.wtcharge).to eq(187.2)
|
||
3 years ago
|
expect(record_from_db["wsupchrg"]).to eq(30.12)
|
||
3 years ago
|
expect(record_from_db["wpschrge"]).to eq(25.13)
|
||
3 years ago
|
expect(record_from_db["wscharge"]).to eq(30.98)
|
||
3 years ago
|
expect(record_from_db["wrent"]).to eq(100.97)
|
||
3 years ago
|
expect(record_from_db["wtcharge"]).to eq(187.2)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
3 years ago
|
context "when the owning organisation is a LA" do
|
||
2 years ago
|
before { lettings_log.owning_organisation.update!(provider_type: "LA") }
|
||
3 years ago
|
|
||
|
context "when the rent type is intermediate rent and supported housing" do
|
||
|
it "correctly derives and saves lettype" do
|
||
2 years ago
|
lettings_log.update!(rent_type: 4, needstype: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select lettype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.lettype).to eq(12)
|
||
3 years ago
|
expect(record_from_db["lettype"]).to eq(12)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the rent type is intermediate rent and general needs housing" do
|
||
|
it "correctly derives and saves lettype" do
|
||
2 years ago
|
lettings_log.update!(rent_type: 4, needstype: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select lettype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.lettype).to eq(11)
|
||
3 years ago
|
expect(record_from_db["lettype"]).to eq(11)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the rent type is affordable rent and supported housing" do
|
||
|
it "correctly derives and saves lettype" do
|
||
2 years ago
|
lettings_log.update!(rent_type: 2, needstype: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select lettype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.lettype).to eq(8)
|
||
3 years ago
|
expect(record_from_db["lettype"]).to eq(8)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the rent type is affordable rent and general needs housing" do
|
||
|
it "correctly derives and saves lettype" do
|
||
2 years ago
|
lettings_log.update!(rent_type: 2, needstype: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select lettype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.lettype).to eq(7)
|
||
3 years ago
|
expect(record_from_db["lettype"]).to eq(7)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the rent type is social rent and supported housing" do
|
||
|
it "correctly derives and saves lettype" do
|
||
2 years ago
|
lettings_log.update!(rent_type: 0, needstype: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select lettype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.lettype).to eq(4)
|
||
3 years ago
|
expect(record_from_db["lettype"]).to eq(4)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the rent type is social rent and general needs housing" do
|
||
|
it "correctly derives and saves lettype" do
|
||
2 years ago
|
lettings_log.update!(rent_type: 0, needstype: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select lettype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.lettype).to eq(3)
|
||
3 years ago
|
expect(record_from_db["lettype"]).to eq(3)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives and saves day, month, year from start date" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select startdate from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["startdate"].day).to eq(10)
|
||
|
expect(record_from_db["startdate"].month).to eq(10)
|
||
|
expect(record_from_db["startdate"].year).to eq(2021)
|
||
|
end
|
||
3 years ago
|
|
||
3 years ago
|
context "when any charge field is set" do
|
||
|
before do
|
||
2 years ago
|
lettings_log.update!(pscharge: 10)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "derives that any blank ones are 0" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select supcharg, scharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["supcharg"].to_f).to eq(0.0)
|
||
|
expect(record_from_db["scharge"].to_f).to eq(0.0)
|
||
|
end
|
||
|
end
|
||
|
|
||
3 years ago
|
def check_postcode_fields(postcode_field)
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field} from lettings_logs where id=#{address_lettings_log.id}").to_a[0]
|
||
|
expect(address_lettings_log[postcode_field]).to eq("M1 1AE")
|
||
2 years ago
|
expect(record_from_db[postcode_field]).to eq("M1 1AE")
|
||
3 years ago
|
end
|
||
|
|
||
|
def check_previous_postcode_fields(postcode_field)
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field} from lettings_logs where id=#{address_lettings_log.id}").to_a[0]
|
||
|
expect(address_lettings_log[postcode_field]).to eq("M1 1AE")
|
||
2 years ago
|
expect(record_from_db[postcode_field]).to eq("M1 1AE")
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
3 years ago
|
context "when saving addresses" do
|
||
3 years ago
|
before do
|
||
|
stub_request(:get, /api.postcodes.io/)
|
||
3 years ago
|
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\",\"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {})
|
||
3 years ago
|
end
|
||
|
|
||
2 years ago
|
let!(:address_lettings_log) do
|
||
3 years ago
|
described_class.create({
|
||
3 years ago
|
managing_organisation: owning_organisation,
|
||
|
owning_organisation:,
|
||
3 years ago
|
created_by: created_by_user,
|
||
3 years ago
|
postcode_known: 1,
|
||
3 years ago
|
postcode_full: "M1 1AE",
|
||
3 years ago
|
})
|
||
|
end
|
||
|
|
||
3 years ago
|
def check_property_postcode_fields
|
||
3 years ago
|
check_postcode_fields("postcode_full")
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly formats previous postcode" do
|
||
2 years ago
|
address_lettings_log.update!(postcode_full: "M1 1AE")
|
||
3 years ago
|
check_property_postcode_fields
|
||
|
|
||
2 years ago
|
address_lettings_log.update!(postcode_full: "m1 1ae")
|
||
3 years ago
|
check_property_postcode_fields
|
||
|
|
||
2 years ago
|
address_lettings_log.update!(postcode_full: "m11Ae")
|
||
3 years ago
|
check_property_postcode_fields
|
||
|
|
||
2 years ago
|
address_lettings_log.update!(postcode_full: "m11ae")
|
||
3 years ago
|
check_property_postcode_fields
|
||
|
end
|
||
|
|
||
3 years ago
|
it "correctly infers la" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select la from lettings_logs where id=#{address_lettings_log.id}").to_a[0]
|
||
|
expect(address_lettings_log.la).to eq("E08000003")
|
||
3 years ago
|
expect(record_from_db["la"]).to eq("E08000003")
|
||
|
end
|
||
|
|
||
3 years ago
|
it "errors if the property postcode is emptied" do
|
||
2 years ago
|
expect { address_lettings_log.update!({ postcode_full: "" }) }
|
||
3 years ago
|
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
3 years ago
|
it "errors if the property postcode is not valid" do
|
||
2 years ago
|
expect { address_lettings_log.update!({ postcode_full: "invalid_postcode" }) }
|
||
3 years ago
|
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
|
||
3 years ago
|
end
|
||
|
|
||
3 years ago
|
context "when the local authority lookup times out" do
|
||
|
before do
|
||
|
allow(Timeout).to receive(:timeout).and_raise(Timeout::Error)
|
||
|
end
|
||
|
|
||
|
it "logs a warning" do
|
||
|
expect(Rails.logger).to receive(:warn).with("Postcodes.io lookup timed out")
|
||
2 years ago
|
address_lettings_log.update!({ postcode_known: 1, postcode_full: "M1 1AD" })
|
||
3 years ago
|
end
|
||
|
end
|
||
|
|
||
3 years ago
|
it "correctly resets all fields if property postcode not known" do
|
||
2 years ago
|
address_lettings_log.update!({ postcode_known: 0 })
|
||
3 years ago
|
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select la, postcode_full from lettings_logs where id=#{address_lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["postcode_full"]).to eq(nil)
|
||
2 years ago
|
expect(address_lettings_log.la).to eq(nil)
|
||
3 years ago
|
expect(record_from_db["la"]).to eq(nil)
|
||
|
end
|
||
3 years ago
|
|
||
3 years ago
|
it "changes the LA if property postcode changes from not known to known and provided" do
|
||
2 years ago
|
address_lettings_log.update!({ postcode_known: 0 })
|
||
|
address_lettings_log.update!({ la: "E09000033" })
|
||
3 years ago
|
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select la, postcode_full from lettings_logs where id=#{address_lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["postcode_full"]).to eq(nil)
|
||
2 years ago
|
expect(address_lettings_log.la).to eq("E09000033")
|
||
3 years ago
|
expect(record_from_db["la"]).to eq("E09000033")
|
||
|
|
||
2 years ago
|
address_lettings_log.update!({ postcode_known: 1, postcode_full: "M1 1AD" })
|
||
3 years ago
|
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select la, postcode_full from lettings_logs where id=#{address_lettings_log.id}").to_a[0]
|
||
2 years ago
|
expect(record_from_db["postcode_full"]).to eq("M1 1AD")
|
||
2 years ago
|
expect(address_lettings_log.la).to eq("E08000003")
|
||
3 years ago
|
expect(record_from_db["la"]).to eq("E08000003")
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
3 years ago
|
context "when saving previous address" do
|
||
|
before do
|
||
|
stub_request(:get, /api.postcodes.io/)
|
||
3 years ago
|
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {})
|
||
3 years ago
|
end
|
||
|
|
||
2 years ago
|
let!(:address_lettings_log) do
|
||
3 years ago
|
described_class.create({
|
||
3 years ago
|
managing_organisation: owning_organisation,
|
||
|
owning_organisation:,
|
||
3 years ago
|
created_by: created_by_user,
|
||
3 years ago
|
ppcodenk: 1,
|
||
3 years ago
|
ppostcode_full: "M1 1AE",
|
||
3 years ago
|
})
|
||
|
end
|
||
|
|
||
3 years ago
|
def previous_postcode_fields
|
||
|
check_previous_postcode_fields("ppostcode_full")
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly formats previous postcode" do
|
||
2 years ago
|
address_lettings_log.update!(ppostcode_full: "M1 1AE")
|
||
3 years ago
|
previous_postcode_fields
|
||
3 years ago
|
|
||
2 years ago
|
address_lettings_log.update!(ppostcode_full: "m1 1ae")
|
||
3 years ago
|
previous_postcode_fields
|
||
3 years ago
|
|
||
2 years ago
|
address_lettings_log.update!(ppostcode_full: "m11Ae")
|
||
3 years ago
|
previous_postcode_fields
|
||
3 years ago
|
|
||
2 years ago
|
address_lettings_log.update!(ppostcode_full: "m11ae")
|
||
3 years ago
|
previous_postcode_fields
|
||
3 years ago
|
end
|
||
|
|
||
3 years ago
|
it "correctly infers prevloc" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select prevloc from lettings_logs where id=#{address_lettings_log.id}").to_a[0]
|
||
|
expect(address_lettings_log.prevloc).to eq("E08000003")
|
||
3 years ago
|
expect(record_from_db["prevloc"]).to eq("E08000003")
|
||
|
end
|
||
|
|
||
|
it "errors if the previous postcode is emptied" do
|
||
2 years ago
|
expect { address_lettings_log.update!({ ppostcode_full: "" }) }
|
||
3 years ago
|
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
|
||
|
end
|
||
|
|
||
|
it "errors if the previous postcode is not valid" do
|
||
2 years ago
|
expect { address_lettings_log.update!({ ppostcode_full: "invalid_postcode" }) }
|
||
3 years ago
|
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
|
||
|
end
|
||
|
|
||
|
it "correctly resets all fields if previous postcode not known" do
|
||
2 years ago
|
address_lettings_log.update!({ ppcodenk: 0 })
|
||
3 years ago
|
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from lettings_logs where id=#{address_lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["ppostcode_full"]).to eq(nil)
|
||
2 years ago
|
expect(address_lettings_log.prevloc).to eq(nil)
|
||
3 years ago
|
expect(record_from_db["prevloc"]).to eq(nil)
|
||
|
end
|
||
|
|
||
3 years ago
|
it "correctly resets la if la is not known" do
|
||
2 years ago
|
address_lettings_log.update!({ ppcodenk: 0 })
|
||
|
address_lettings_log.update!({ previous_la_known: 1, prevloc: "S92000003" })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select prevloc from lettings_logs where id=#{address_lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["prevloc"]).to eq("S92000003")
|
||
2 years ago
|
expect(address_lettings_log.prevloc).to eq("S92000003")
|
||
3 years ago
|
|
||
2 years ago
|
address_lettings_log.update!({ previous_la_known: 0 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select prevloc from lettings_logs where id=#{address_lettings_log.id}").to_a[0]
|
||
|
expect(address_lettings_log.prevloc).to eq(nil)
|
||
3 years ago
|
expect(record_from_db["prevloc"]).to eq(nil)
|
||
|
end
|
||
|
|
||
3 years ago
|
it "changes the prevloc if previous postcode changes from not known to known and provided" do
|
||
2 years ago
|
address_lettings_log.update!({ ppcodenk: 0 })
|
||
|
address_lettings_log.update!({ previous_la_known: 1, prevloc: "E09000033" })
|
||
3 years ago
|
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from lettings_logs where id=#{address_lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["ppostcode_full"]).to eq(nil)
|
||
2 years ago
|
expect(address_lettings_log.prevloc).to eq("E09000033")
|
||
3 years ago
|
expect(record_from_db["prevloc"]).to eq("E09000033")
|
||
|
|
||
2 years ago
|
address_lettings_log.update!({ ppcodenk: 0, ppostcode_full: "M1 1AD" })
|
||
3 years ago
|
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from lettings_logs where id=#{address_lettings_log.id}").to_a[0]
|
||
2 years ago
|
expect(record_from_db["ppostcode_full"]).to eq("M1 1AD")
|
||
2 years ago
|
expect(address_lettings_log.prevloc).to eq("E08000003")
|
||
3 years ago
|
expect(record_from_db["prevloc"]).to eq("E08000003")
|
||
|
end
|
||
|
end
|
||
|
|
||
3 years ago
|
context "when saving rent and charges" do
|
||
2 years ago
|
let!(:lettings_log) do
|
||
3 years ago
|
described_class.create({
|
||
3 years ago
|
managing_organisation: owning_organisation,
|
||
|
owning_organisation:,
|
||
3 years ago
|
created_by: created_by_user,
|
||
3 years ago
|
brent: 5.77,
|
||
|
scharge: 10.01,
|
||
3 years ago
|
pscharge: 3,
|
||
3 years ago
|
supcharg: 12.2,
|
||
3 years ago
|
})
|
||
|
end
|
||
|
|
||
|
it "correctly sums rental charges" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select tcharge from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["tcharge"]).to eq(30.98)
|
||
3 years ago
|
end
|
||
|
end
|
||
|
|
||
3 years ago
|
context "when validating household members derived vars" do
|
||
2 years ago
|
let!(:household_lettings_log) do
|
||
3 years ago
|
described_class.create!({
|
||
3 years ago
|
managing_organisation: owning_organisation,
|
||
|
owning_organisation:,
|
||
3 years ago
|
created_by: created_by_user,
|
||
3 years ago
|
hhmemb: 3,
|
||
3 years ago
|
relat2: "X",
|
||
3 years ago
|
relat3: "C",
|
||
|
relat4: "X",
|
||
|
relat5: "C",
|
||
3 years ago
|
relat7: "C",
|
||
3 years ago
|
relat8: "X",
|
||
3 years ago
|
age1: 22,
|
||
3 years ago
|
age2: 16,
|
||
3 years ago
|
age4: 60,
|
||
3 years ago
|
age6: 88,
|
||
3 years ago
|
age7: 14,
|
||
3 years ago
|
age8: 42,
|
||
3 years ago
|
})
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves totchild" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select totchild from lettings_logs where id=#{household_lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["totchild"]).to eq(3)
|
||
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives and saves totelder" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select totelder from lettings_logs where id=#{household_lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["totelder"]).to eq(2)
|
||
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives and saves totadult" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select totadult from lettings_logs where id=#{household_lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["totadult"]).to eq(3)
|
||
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives economic status for tenants under 16" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select ecstat7 from lettings_logs where id=#{household_lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["ecstat7"]).to eq(9)
|
||
|
end
|
||
|
|
||
|
it "correctly resets economic status when age changes from under 16" do
|
||
2 years ago
|
household_lettings_log.update!(age7_known: 0, age7: 17)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select ecstat7 from lettings_logs where id=#{household_lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["ecstat7"]).to eq(nil)
|
||
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
it "correctly derives and saves has_benefits" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select has_benefits from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["has_benefits"]).to eq(1)
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
context "when it is a renewal" do
|
||
2 years ago
|
let!(:lettings_log) do
|
||
3 years ago
|
described_class.create({
|
||
3 years ago
|
managing_organisation: owning_organisation,
|
||
|
owning_organisation:,
|
||
3 years ago
|
created_by: created_by_user,
|
||
3 years ago
|
renewal: 1,
|
||
3 years ago
|
startdate: Time.zone.local(2021, 4, 10),
|
||
3 years ago
|
})
|
||
|
end
|
||
|
|
||
3 years ago
|
it "correctly derives and saves waityear" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select waityear from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["waityear"]).to eq(2)
|
||
2 years ago
|
expect(lettings_log["waityear"]).to eq(2)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves underoccupation_benefitcap if year is 2021" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select underoccupation_benefitcap from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["underoccupation_benefitcap"]).to eq(2)
|
||
2 years ago
|
expect(lettings_log["underoccupation_benefitcap"]).to eq(2)
|
||
3 years ago
|
end
|
||
|
|
||
3 years ago
|
it "correctly derives and saves prevten" do
|
||
2 years ago
|
lettings_log.managing_organisation.update!({ provider_type: "PRP" })
|
||
|
lettings_log.update!({ needstype: 1 })
|
||
3 years ago
|
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select prevten from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["prevten"]).to eq(32)
|
||
2 years ago
|
expect(lettings_log["prevten"]).to eq(32)
|
||
3 years ago
|
|
||
2 years ago
|
lettings_log.managing_organisation.update!({ provider_type: "LA" })
|
||
|
lettings_log.update!({ needstype: 1 })
|
||
3 years ago
|
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select prevten from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["prevten"]).to eq(30)
|
||
2 years ago
|
expect(lettings_log["prevten"]).to eq(30)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "correctly derives and saves referral" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select referral from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["referral"]).to eq(0)
|
||
2 years ago
|
expect(lettings_log["referral"]).to eq(0)
|
||
3 years ago
|
end
|
||
|
end
|
||
3 years ago
|
|
||
3 years ago
|
context "when answering the household characteristics questions" do
|
||
2 years ago
|
let!(:lettings_log) do
|
||
3 years ago
|
described_class.create({
|
||
3 years ago
|
managing_organisation: owning_organisation,
|
||
|
owning_organisation:,
|
||
3 years ago
|
created_by: created_by_user,
|
||
3 years ago
|
age1_known: 1,
|
||
|
sex1: "R",
|
||
3 years ago
|
relat2: "R",
|
||
3 years ago
|
ecstat1: 10,
|
||
|
})
|
||
|
end
|
||
|
|
||
|
it "correctly derives and saves refused" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select refused from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["refused"]).to eq(1)
|
||
2 years ago
|
expect(lettings_log["refused"]).to eq(1)
|
||
3 years ago
|
end
|
||
|
end
|
||
|
|
||
3 years ago
|
context "when it is supported housing and a care home charge has been supplied" do
|
||
2 years ago
|
let!(:lettings_log) do
|
||
3 years ago
|
described_class.create({
|
||
3 years ago
|
managing_organisation: owning_organisation,
|
||
|
owning_organisation:,
|
||
3 years ago
|
created_by: created_by_user,
|
||
3 years ago
|
needstype: 2,
|
||
3 years ago
|
})
|
||
|
end
|
||
|
|
||
|
context "when the care home charge is paid bi-weekly" do
|
||
|
it "correctly derives and saves weekly care home charge" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 100, period: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(50.0)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(50.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 100.12, period: 2)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(50.06)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(50.06)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the care home charge is paid every 4 weeks" do
|
||
|
it "correctly derives and saves weekly care home charge" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 120, period: 3)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(30.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 100.12, period: 3)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(25.03)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(25.03)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the care home charge is paid every calendar month" do
|
||
|
it "correctly derives and saves weekly care home charge" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 130, period: 4)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(30.0)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(30.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 100.12, period: 4)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(23.10)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(23.10)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the care home charge is paid weekly for 50 weeks" do
|
||
|
it "correctly derives and saves weekly care home charge" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 130, period: 5)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(125.0)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(125.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 100.12, period: 5)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(96.27)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(96.27)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the care home charge is paid weekly for 49 weeks" do
|
||
|
it "correctly derives and saves weekly care home charge" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 130, period: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(122.5)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(122.5)
|
||
|
end
|
||
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 100.12, period: 6)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(94.34)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(94.34)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the care home charge is paid weekly for 48 weeks" do
|
||
|
it "correctly derives and saves weekly care home charge" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 130, period: 7)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(120.0)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(120.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 100.12, period: 7)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(92.42)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(92.42)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the care home charge is paid weekly for 47 weeks" do
|
||
|
it "correctly derives and saves weekly care home charge" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 130, period: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(117.5)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(117.5)
|
||
|
end
|
||
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 100.12, period: 8)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(90.49)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(90.49)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the care home charge is paid weekly for 46 weeks" do
|
||
|
it "correctly derives and saves weekly care home charge" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 130, period: 9)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(115.0)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(115.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 100.12, period: 9)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(88.57)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(88.57)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when the care home charge is paid weekly for 52 weeks" do
|
||
|
it "correctly derives and saves weekly care home charge" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 130, period: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(130.0)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(130.0)
|
||
|
end
|
||
|
|
||
|
it "correctly derives floats" do
|
||
2 years ago
|
lettings_log.update!(chcharge: 100.12, period: 1)
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
|
expect(lettings_log.wchchrg).to eq(100.12)
|
||
3 years ago
|
expect(record_from_db["wchchrg"]).to eq(100.12)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
context "when the data provider is filling in the reason for the property being vacant" do
|
||
2 years ago
|
let!(:first_let_lettings_log) do
|
||
3 years ago
|
described_class.create({
|
||
3 years ago
|
managing_organisation: owning_organisation,
|
||
|
owning_organisation:,
|
||
3 years ago
|
created_by: created_by_user,
|
||
3 years ago
|
first_time_property_let_as_social_housing: 1,
|
||
|
})
|
||
|
end
|
||
|
|
||
2 years ago
|
let!(:relet_lettings_log) do
|
||
3 years ago
|
described_class.create({
|
||
3 years ago
|
managing_organisation: owning_organisation,
|
||
|
owning_organisation:,
|
||
3 years ago
|
created_by: created_by_user,
|
||
3 years ago
|
first_time_property_let_as_social_housing: 0,
|
||
|
})
|
||
|
end
|
||
|
|
||
|
it "the newprop variable is correctly derived and saved as 1 for a first let vacancy reason" do
|
||
2 years ago
|
first_let_lettings_log.update!({ rsnvac: 15 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select newprop from lettings_logs where id=#{first_let_lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["newprop"]).to eq(1)
|
||
2 years ago
|
expect(first_let_lettings_log["newprop"]).to eq(1)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "the newprop variable is correctly derived and saved as 2 for anything that is not a first let vacancy reason" do
|
||
2 years ago
|
relet_lettings_log.update!({ rsnvac: 2 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select newprop from lettings_logs where id=#{relet_lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["newprop"]).to eq(2)
|
||
2 years ago
|
expect(relet_lettings_log["newprop"]).to eq(2)
|
||
3 years ago
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
context "when a total shortfall is provided" do
|
||
|
it "derives that tshortfall is known" do
|
||
2 years ago
|
lettings_log.update!({ tshortfall: 10 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select tshortfall_known from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["tshortfall_known"]).to eq(0)
|
||
2 years ago
|
expect(lettings_log["tshortfall_known"]).to eq(0)
|
||
3 years ago
|
end
|
||
|
end
|
||
3 years ago
|
|
||
2 years ago
|
context "when a lettings log is a supported housing log" do
|
||
2 years ago
|
let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") }
|
||
|
|
||
|
before do
|
||
2 years ago
|
lettings_log.needstype = 2
|
||
2 years ago
|
allow(FormHandler.instance).to receive(:get_form).and_return(real_2021_2022_form)
|
||
|
end
|
||
3 years ago
|
|
||
|
context "and a scheme with a single log is selected" do
|
||
|
let(:scheme) { FactoryBot.create(:scheme) }
|
||
|
let!(:location) { FactoryBot.create(:location, scheme:) }
|
||
|
|
||
2 years ago
|
before { lettings_log.update!(scheme:) }
|
||
3 years ago
|
|
||
|
it "derives the scheme location" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select location_id from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["location_id"]).to eq(location.id)
|
||
2 years ago
|
expect(lettings_log["location_id"]).to eq(location.id)
|
||
3 years ago
|
end
|
||
|
end
|
||
2 years ago
|
|
||
|
context "and not renewal" do
|
||
|
let(:scheme) { FactoryBot.create(:scheme) }
|
||
2 years ago
|
let(:location) { FactoryBot.create(:location, scheme:, postcode: "M11AE", type_of_unit: 1, mobility_type: "W") }
|
||
2 years ago
|
|
||
2 years ago
|
let(:supported_housing_lettings_log) do
|
||
2 years ago
|
described_class.create!({
|
||
|
managing_organisation: owning_organisation,
|
||
|
owning_organisation:,
|
||
|
created_by: created_by_user,
|
||
|
needstype: 2,
|
||
|
scheme_id: scheme.id,
|
||
|
location_id: location.id,
|
||
|
renewal: 0,
|
||
|
})
|
||
|
end
|
||
|
|
||
2 years ago
|
before do
|
||
|
stub_request(:get, /api.postcodes.io/)
|
||
|
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\",\"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {})
|
||
|
end
|
||
|
|
||
2 years ago
|
it "correctly infers and saves la" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("SELECT la from lettings_logs WHERE id=#{supported_housing_lettings_log.id}").to_a[0]
|
||
2 years ago
|
expect(record_from_db["la"]).to be_nil
|
||
2 years ago
|
expect(supported_housing_lettings_log.la).to eq("E08000003")
|
||
2 years ago
|
end
|
||
|
|
||
|
it "correctly infers and saves postcode" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("SELECT postcode_full from lettings_logs WHERE id=#{supported_housing_lettings_log.id}").to_a[0]
|
||
2 years ago
|
expect(record_from_db["postcode_full"]).to be_nil
|
||
2 years ago
|
expect(supported_housing_lettings_log.postcode_full).to eq("M1 1AE")
|
||
2 years ago
|
end
|
||
|
|
||
2 years ago
|
it "unittype_sh method returns the type_of_unit of the location" do
|
||
2 years ago
|
expect(supported_housing_lettings_log.unittype_sh).to eq(1)
|
||
2 years ago
|
end
|
||
|
|
||
|
it "correctly infers and saves wchair" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("SELECT wchair from lettings_logs WHERE id=#{supported_housing_lettings_log.id}").to_a[0]
|
||
2 years ago
|
expect(record_from_db["wchair"]).to eq(1)
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "and renewal" do
|
||
|
let(:scheme) { FactoryBot.create(:scheme) }
|
||
|
let(:location) { FactoryBot.create(:location, scheme:) }
|
||
|
|
||
2 years ago
|
let!(:supported_housing_lettings_log) do
|
||
2 years ago
|
described_class.create!({
|
||
|
managing_organisation: owning_organisation,
|
||
|
owning_organisation:,
|
||
|
created_by: created_by_user,
|
||
|
needstype: 2,
|
||
|
scheme_id: scheme.id,
|
||
|
location_id: location.id,
|
||
|
renewal: 1,
|
||
|
startdate: Time.zone.now,
|
||
|
})
|
||
|
end
|
||
|
|
||
|
it "correcly infers and saves the renewal date" do
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("SELECT voiddate from lettings_logs where id=#{supported_housing_lettings_log.id}").to_a[0]
|
||
|
expect(record_from_db["voiddate"].to_i).to eq(supported_housing_lettings_log.startdate.to_i)
|
||
2 years ago
|
end
|
||
|
end
|
||
3 years ago
|
end
|
||
2 years ago
|
|
||
|
context "when saving accessibility needs" do
|
||
|
it "derives housingneeds_h as true if 'Don't know' is selected for housingneeds" do
|
||
2 years ago
|
lettings_log.update!({ housingneeds: 3 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
2 years ago
|
not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_g]
|
||
|
not_selected_housingneeds.each do |housingneed|
|
||
|
expect(record_from_db[housingneed]).to eq(0)
|
||
2 years ago
|
expect(lettings_log[housingneed]).to eq(0)
|
||
2 years ago
|
end
|
||
|
expect(record_from_db["housingneeds_h"]).to eq(1)
|
||
2 years ago
|
expect(lettings_log["housingneeds_h"]).to eq(1)
|
||
2 years ago
|
end
|
||
|
|
||
|
it "derives housingneeds_g as true if 'No' is selected for housingneeds" do
|
||
2 years ago
|
lettings_log.update!({ housingneeds: 2 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
2 years ago
|
not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_h]
|
||
|
not_selected_housingneeds.each do |housingneed|
|
||
|
expect(record_from_db[housingneed]).to eq(0)
|
||
2 years ago
|
expect(lettings_log[housingneed]).to eq(0)
|
||
2 years ago
|
end
|
||
|
expect(record_from_db["housingneeds_g"]).to eq(1)
|
||
2 years ago
|
expect(lettings_log["housingneeds_g"]).to eq(1)
|
||
2 years ago
|
end
|
||
|
|
||
|
it "derives housingneeds_a as true if 'Fully wheelchair accessible' is selected for housingneeds_type" do
|
||
2 years ago
|
lettings_log.update!({ housingneeds: 1, housingneeds_type: 0 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
2 years ago
|
not_selected_housingneeds = %w[housingneeds_b housingneeds_c housingneeds_f housingneeds_g housingneeds_h]
|
||
|
not_selected_housingneeds.each do |housingneed|
|
||
|
expect(record_from_db[housingneed]).to eq(0)
|
||
2 years ago
|
expect(lettings_log[housingneed]).to eq(0)
|
||
2 years ago
|
end
|
||
|
expect(record_from_db["housingneeds_a"]).to eq(1)
|
||
2 years ago
|
expect(lettings_log["housingneeds_a"]).to eq(1)
|
||
2 years ago
|
end
|
||
|
|
||
|
it "derives housingneeds_b as true if 'Wheelchair access to essential rooms' is selected for housingneeds_type" do
|
||
2 years ago
|
lettings_log.update!({ housingneeds: 1, housingneeds_type: 1 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
2 years ago
|
not_selected_housingneeds = %w[housingneeds_a housingneeds_c housingneeds_f housingneeds_g housingneeds_h]
|
||
|
not_selected_housingneeds.each do |housingneed|
|
||
|
expect(record_from_db[housingneed]).to eq(0)
|
||
2 years ago
|
expect(lettings_log[housingneed]).to eq(0)
|
||
2 years ago
|
end
|
||
|
expect(record_from_db["housingneeds_b"]).to eq(1)
|
||
2 years ago
|
expect(lettings_log["housingneeds_b"]).to eq(1)
|
||
2 years ago
|
end
|
||
|
|
||
|
it "derives housingneeds_c if 'Level access housing' is selected for housingneeds_type" do
|
||
2 years ago
|
lettings_log.update!({ housingneeds: 1, housingneeds_type: 2 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
2 years ago
|
not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_f housingneeds_g housingneeds_h]
|
||
|
not_selected_housingneeds.each do |housingneed|
|
||
|
expect(record_from_db[housingneed]).to eq(0)
|
||
2 years ago
|
expect(lettings_log[housingneed]).to eq(0)
|
||
2 years ago
|
end
|
||
|
expect(record_from_db["housingneeds_c"]).to eq(1)
|
||
2 years ago
|
expect(lettings_log["housingneeds_c"]).to eq(1)
|
||
2 years ago
|
end
|
||
|
|
||
|
it "derives housingneeds_f if 'Yes' is selected for housingneeds_other" do
|
||
2 years ago
|
lettings_log.update!({ housingneeds: 1, housingneeds_other: 1 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
2 years ago
|
not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_c housingneeds_g housingneeds_h]
|
||
|
not_selected_housingneeds.each do |housingneed|
|
||
|
expect(record_from_db[housingneed]).to eq(0)
|
||
2 years ago
|
expect(lettings_log[housingneed]).to eq(0)
|
||
2 years ago
|
end
|
||
|
expect(record_from_db["housingneeds_f"]).to eq(1)
|
||
2 years ago
|
expect(lettings_log["housingneeds_f"]).to eq(1)
|
||
2 years ago
|
end
|
||
|
|
||
|
it "clears previously set housingneeds if 'No' is selected for housingneeds" do
|
||
2 years ago
|
lettings_log.update!({ housingneeds: 1, housingneeds_type: 2, housingneeds_other: 1 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
2 years ago
|
expect(record_from_db["housingneeds_c"]).to eq(1)
|
||
2 years ago
|
expect(lettings_log["housingneeds_c"]).to eq(1)
|
||
2 years ago
|
expect(record_from_db["housingneeds_f"]).to eq(1)
|
||
2 years ago
|
expect(lettings_log["housingneeds_f"]).to eq(1)
|
||
2 years ago
|
|
||
2 years ago
|
lettings_log.update!({ housingneeds: 2 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
2 years ago
|
not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_h]
|
||
|
not_selected_housingneeds.each do |housingneed|
|
||
|
expect(record_from_db[housingneed]).to eq(0)
|
||
2 years ago
|
expect(lettings_log[housingneed]).to eq(0)
|
||
2 years ago
|
end
|
||
|
expect(record_from_db["housingneeds_g"]).to eq(1)
|
||
2 years ago
|
expect(lettings_log["housingneeds_g"]).to eq(1)
|
||
2 years ago
|
end
|
||
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
describe "optional fields" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log) }
|
||
3 years ago
|
|
||
|
context "when tshortfall is marked as not known" do
|
||
|
it "makes tshortfall optional" do
|
||
2 years ago
|
lettings_log.update!({ tshortfall: nil, tshortfall_known: 1 })
|
||
|
expect(lettings_log.optional_fields).to include("tshortfall")
|
||
3 years ago
|
end
|
||
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
describe "resetting invalidated fields" do
|
||
|
context "when a question that has already been answered, no longer has met dependencies" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress, cbl: 1, preg_occ: 2, wchair: 1) }
|
||
3 years ago
|
|
||
|
it "clears the answer" do
|
||
2 years ago
|
expect { lettings_log.update!(preg_occ: nil) }.to change(lettings_log, :cbl).from(1).to(nil)
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
context "when the question type does not have answer options" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress, housingneeds_a: 1, age1: 19) }
|
||
3 years ago
|
|
||
|
it "clears the answer" do
|
||
2 years ago
|
expect { lettings_log.update!(housingneeds_a: 0) }.to change(lettings_log, :age1).from(19).to(nil)
|
||
3 years ago
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
context "when the question type has answer options" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress, illness: 1, illness_type_1: 1) }
|
||
3 years ago
|
|
||
|
it "clears the answer" do
|
||
2 years ago
|
expect { lettings_log.update!(illness: 0) }.to change(lettings_log, :illness_type_1).from(1).to(nil)
|
||
3 years ago
|
end
|
||
|
end
|
||
3 years ago
|
end
|
||
|
|
||
3 years ago
|
context "with two pages having the same question key, only one's dependency is met" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress, cbl: 0, preg_occ: 2, wchair: 1) }
|
||
3 years ago
|
|
||
3 years ago
|
it "does not clear the value for answers that apply to both pages" do
|
||
2 years ago
|
expect(lettings_log.cbl).to eq(0)
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
it "does clear the value for answers that do not apply for invalidated page" do
|
||
2 years ago
|
lettings_log.update!({ wchair: 1, sex2: "F", age2: 33 })
|
||
|
lettings_log.update!({ cbl: 1 })
|
||
|
lettings_log.update!({ preg_occ: 1 })
|
||
3 years ago
|
|
||
2 years ago
|
expect(lettings_log.cbl).to eq(nil)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
3 years ago
|
context "when a non select question associated with several pages is routed to" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress, period: 2) }
|
||
3 years ago
|
|
||
|
it "does not clear the answer value" do
|
||
2 years ago
|
lettings_log.update!({ offered: 4 })
|
||
|
lettings_log.reload
|
||
|
expect(lettings_log.offered).to eq(4)
|
||
3 years ago
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when the lettings log does not have a valid form set yet" do
|
||
|
let(:lettings_log) { FactoryBot.create(:lettings_log) }
|
||
3 years ago
|
|
||
|
it "does not throw an error" do
|
||
2 years ago
|
expect { lettings_log.update(startdate: Time.zone.local(2015, 1, 1)) }.not_to raise_error
|
||
3 years ago
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
context "when it changes from a renewal to not a renewal" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log) }
|
||
3 years ago
|
|
||
3 years ago
|
it "resets inferred waityear value" do
|
||
2 years ago
|
lettings_log.update!({ renewal: 1 })
|
||
3 years ago
|
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select waityear from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["waityear"]).to eq(2)
|
||
2 years ago
|
expect(lettings_log["waityear"]).to eq(2)
|
||
3 years ago
|
|
||
2 years ago
|
lettings_log.update!({ renewal: 0 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select waityear from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["waityear"]).to eq(nil)
|
||
2 years ago
|
expect(lettings_log["waityear"]).to eq(nil)
|
||
3 years ago
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when it changes from a supported housing to not a supported housing" do
|
||
|
let(:location) { FactoryBot.create(:location, mobility_type: "A", postcode: "SW1P 4DG") }
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, location:) }
|
||
2 years ago
|
|
||
|
it "resets inferred wchair value" do
|
||
2 years ago
|
lettings_log.update!({ needstype: 2 })
|
||
2 years ago
|
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select wchair from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
2 years ago
|
expect(record_from_db["wchair"]).to eq(2)
|
||
2 years ago
|
expect(lettings_log["wchair"]).to eq(2)
|
||
2 years ago
|
|
||
2 years ago
|
lettings_log.update!({ needstype: 1 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select needstype from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
2 years ago
|
expect(record_from_db["wchair"]).to eq(nil)
|
||
2 years ago
|
expect(lettings_log["wchair"]).to eq(nil)
|
||
2 years ago
|
end
|
||
|
|
||
|
it "resets location" do
|
||
2 years ago
|
lettings_log.update!({ needstype: 2 })
|
||
2 years ago
|
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select location_id from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
2 years ago
|
expect(record_from_db["location_id"]).to eq(location.id)
|
||
2 years ago
|
expect(lettings_log["location_id"]).to eq(location.id)
|
||
|
lettings_log.update!({ needstype: 1 })
|
||
|
record_from_db = ActiveRecord::Base.connection.execute("select location_id from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
2 years ago
|
expect(record_from_db["location_id"]).to eq(nil)
|
||
2 years ago
|
expect(lettings_log["location_id"]).to eq(nil)
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
3 years ago
|
context "when it is not a renewal" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log) }
|
||
3 years ago
|
|
||
3 years ago
|
it "saves waityear value" do
|
||
2 years ago
|
lettings_log.update!({ renewal: 0, waityear: 2 })
|
||
3 years ago
|
|
||
2 years ago
|
record_from_db = ActiveRecord::Base.connection.execute("select waityear from lettings_logs where id=#{lettings_log.id}").to_a[0]
|
||
3 years ago
|
expect(record_from_db["waityear"]).to eq(2)
|
||
2 years ago
|
expect(lettings_log["waityear"]).to eq(2)
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
context "when a support user changes the owning organisation of the log" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, created_by: created_by_user) }
|
||
3 years ago
|
let(:organisation_2) { FactoryBot.create(:organisation) }
|
||
|
|
||
|
it "clears the created by user set" do
|
||
2 years ago
|
expect { lettings_log.update!(owning_organisation: organisation_2) }
|
||
|
.to change { lettings_log.reload.created_by }.from(created_by_user).to(nil)
|
||
3 years ago
|
end
|
||
2 years ago
|
|
||
|
context "when the organisation selected doesn't match the scheme set" do
|
||
|
let(:scheme) { FactoryBot.create(:scheme, owning_organisation: created_by_user.organisation) }
|
||
|
let(:location) { FactoryBot.create(:location, scheme:) }
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, owning_organisation: nil, needstype: 2, scheme_id: scheme.id) }
|
||
2 years ago
|
|
||
|
it "clears the scheme value" do
|
||
2 years ago
|
lettings_log.update!(owning_organisation: organisation_2)
|
||
|
expect(lettings_log.reload.scheme).to be nil
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when the organisation selected still matches the scheme set" do
|
||
|
let(:scheme) { FactoryBot.create(:scheme, owning_organisation: organisation_2) }
|
||
|
let(:location) { FactoryBot.create(:location, scheme:) }
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, owning_organisation: nil, needstype: 2, scheme_id: scheme.id) }
|
||
2 years ago
|
|
||
|
it "does not clear the scheme value" do
|
||
2 years ago
|
lettings_log.update!(owning_organisation: organisation_2)
|
||
|
expect(lettings_log.reload.scheme_id).to eq(scheme.id)
|
||
2 years ago
|
end
|
||
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
describe "tshortfall_unknown?" do
|
||
|
context "when tshortfall is nil" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress, tshortfall_known: nil) }
|
||
3 years ago
|
|
||
|
it "returns false" do
|
||
2 years ago
|
expect(lettings_log.tshortfall_unknown?).to be false
|
||
3 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when tshortfall is No" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress, tshortfall_known: 1) }
|
||
3 years ago
|
|
||
|
it "returns false" do
|
||
2 years ago
|
expect(lettings_log.tshortfall_unknown?).to be true
|
||
3 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when tshortfall is Yes" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress, tshortfall_known: 0) }
|
||
3 years ago
|
|
||
|
it "returns false" do
|
||
2 years ago
|
expect(lettings_log.tshortfall_unknown?).to be false
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
describe "paper trail" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress) }
|
||
3 years ago
|
|
||
|
it "creates a record of changes to a log" do
|
||
2 years ago
|
expect { lettings_log.update!(age1: 64) }.to change(lettings_log.versions, :count).by(1)
|
||
3 years ago
|
end
|
||
|
|
||
2 years ago
|
it "allows lettings logs to be restored to a previous version" do
|
||
|
lettings_log.update!(age1: 63)
|
||
|
expect(lettings_log.paper_trail.previous_version.age1).to eq(17)
|
||
3 years ago
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
describe "soft values for period" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.create(:lettings_log) }
|
||
3 years ago
|
|
||
|
before do
|
||
|
LaRentRange.create!(
|
||
|
ranges_rent_id: "1",
|
||
|
la: "E07000223",
|
||
|
beds: 1,
|
||
|
lettype: 1,
|
||
|
soft_min: 100,
|
||
|
soft_max: 400,
|
||
|
hard_min: 50,
|
||
|
hard_max: 500,
|
||
|
start_year: 2021,
|
||
|
)
|
||
|
|
||
2 years ago
|
lettings_log.la = "E07000223"
|
||
|
lettings_log.lettype = 1
|
||
|
lettings_log.beds = 1
|
||
|
lettings_log.startdate = Time.zone.local(2021, 10, 10)
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when period is weekly for 52 weeks" do
|
||
|
it "returns weekly soft min for 52 weeks" do
|
||
2 years ago
|
lettings_log.period = 1
|
||
|
expect(lettings_log.soft_min_for_period).to eq("100.0 every week")
|
||
3 years ago
|
end
|
||
|
|
||
|
it "returns weekly soft max for 52 weeks" do
|
||
2 years ago
|
lettings_log.period = 1
|
||
|
expect(lettings_log.soft_max_for_period).to eq("400.0 every week")
|
||
3 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when period is weekly for 47 weeks" do
|
||
|
it "returns weekly soft min for 47 weeks" do
|
||
2 years ago
|
lettings_log.period = 8
|
||
|
expect(lettings_log.soft_min_for_period).to eq("110.64 every week")
|
||
3 years ago
|
end
|
||
|
|
||
|
it "returns weekly soft max for 47 weeks" do
|
||
2 years ago
|
lettings_log.period = 8
|
||
|
expect(lettings_log.soft_max_for_period).to eq("442.55 every week")
|
||
3 years ago
|
end
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
describe "scopes" do
|
||
2 years ago
|
let!(:lettings_log_1) { FactoryBot.create(:lettings_log, :in_progress, startdate: Time.utc(2021, 5, 3), created_by: created_by_user) }
|
||
|
let!(:lettings_log_2) { FactoryBot.create(:lettings_log, :completed, startdate: Time.utc(2021, 5, 3), created_by: created_by_user) }
|
||
3 years ago
|
|
||
3 years ago
|
before do
|
||
3 years ago
|
Timecop.freeze(Time.utc(2022, 6, 3))
|
||
2 years ago
|
FactoryBot.create(:lettings_log, startdate: Time.utc(2022, 6, 3))
|
||
3 years ago
|
end
|
||
|
|
||
3 years ago
|
after do
|
||
|
Timecop.unfreeze
|
||
|
end
|
||
|
|
||
3 years ago
|
context "when searching logs" do
|
||
2 years ago
|
let!(:lettings_log_to_search) { FactoryBot.create(:lettings_log, :completed) }
|
||
3 years ago
|
|
||
|
before do
|
||
2 years ago
|
FactoryBot.create_list(:lettings_log, 5, :completed)
|
||
3 years ago
|
end
|
||
|
|
||
|
describe "#filter_by_id" do
|
||
|
it "allows searching by a log ID" do
|
||
2 years ago
|
result = described_class.filter_by_id(lettings_log_to_search.id.to_s)
|
||
3 years ago
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
3 years ago
|
end
|
||
|
end
|
||
|
|
||
|
describe "#filter_by_tenant_code" do
|
||
|
it "allows searching by a Tenant Code" do
|
||
2 years ago
|
result = described_class.filter_by_tenant_code(lettings_log_to_search.tenancycode)
|
||
3 years ago
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when tenant_code has lower case letters" do
|
||
2 years ago
|
let(:matching_tenant_code_lower_case) { lettings_log_to_search.tenancycode.downcase }
|
||
3 years ago
|
|
||
|
it "allows searching by a Tenant Code" do
|
||
|
result = described_class.filter_by_tenant_code(matching_tenant_code_lower_case)
|
||
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
3 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#filter_by_propcode" do
|
||
|
it "allows searching by a Property Reference" do
|
||
2 years ago
|
result = described_class.filter_by_propcode(lettings_log_to_search.propcode)
|
||
3 years ago
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when propcode has lower case letters" do
|
||
2 years ago
|
let(:matching_propcode_lower_case) { lettings_log_to_search.propcode.downcase }
|
||
3 years ago
|
|
||
|
it "allows searching by a Property Reference" do
|
||
|
result = described_class.filter_by_propcode(matching_propcode_lower_case)
|
||
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
3 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#filter_by_postcode" do
|
||
|
it "allows searching by a Property Postcode" do
|
||
2 years ago
|
result = described_class.filter_by_postcode(lettings_log_to_search.postcode_full)
|
||
3 years ago
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
3 years ago
|
end
|
||
2 years ago
|
|
||
2 years ago
|
context "when lettings log is supported housing" do
|
||
2 years ago
|
let(:location) { FactoryBot.create(:location, postcode: "W6 0ST") }
|
||
|
|
||
|
before do
|
||
2 years ago
|
lettings_log_to_search.update!(needstype: 2, location:)
|
||
2 years ago
|
end
|
||
|
|
||
|
it "allows searching by a Property Postcode" do
|
||
|
result = described_class.filter_by_location_postcode("W6 0ST")
|
||
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
2 years ago
|
end
|
||
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
describe "#search_by" do
|
||
|
it "allows searching using ID" do
|
||
2 years ago
|
result = described_class.search_by(lettings_log_to_search.id.to_s)
|
||
3 years ago
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
3 years ago
|
end
|
||
|
|
||
|
it "allows searching using tenancy code" do
|
||
2 years ago
|
result = described_class.search_by(lettings_log_to_search.tenancycode)
|
||
3 years ago
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
3 years ago
|
end
|
||
|
|
||
|
it "allows searching by a Property Reference" do
|
||
2 years ago
|
result = described_class.search_by(lettings_log_to_search.propcode)
|
||
3 years ago
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
3 years ago
|
end
|
||
|
|
||
|
it "allows searching by a Property Postcode" do
|
||
2 years ago
|
result = described_class.search_by(lettings_log_to_search.postcode_full)
|
||
3 years ago
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
3 years ago
|
end
|
||
|
|
||
2 years ago
|
context "when lettings log is supported housing" do
|
||
2 years ago
|
let(:location) { FactoryBot.create(:location, postcode: "W6 0ST") }
|
||
|
|
||
|
before do
|
||
2 years ago
|
lettings_log_to_search.update!(needstype: 2, location:)
|
||
2 years ago
|
end
|
||
|
|
||
|
it "allows searching by a Property Postcode" do
|
||
|
result = described_class.search_by("W6 0ST")
|
||
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
3 years ago
|
context "when postcode has spaces and lower case letters" do
|
||
2 years ago
|
let(:matching_postcode_lower_case_with_spaces) { lettings_log_to_search.postcode_full.downcase.chars.insert(3, " ").join }
|
||
3 years ago
|
|
||
|
it "allows searching by a Property Postcode" do
|
||
|
result = described_class.search_by(matching_postcode_lower_case_with_spaces)
|
||
|
expect(result.count).to eq(1)
|
||
2 years ago
|
expect(result.first.id).to eq lettings_log_to_search.id
|
||
3 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
3 years ago
|
context "when filtering by year" do
|
||
3 years ago
|
before do
|
||
|
Timecop.freeze(Time.utc(2021, 5, 3))
|
||
|
end
|
||
|
|
||
|
after do
|
||
|
Timecop.unfreeze
|
||
|
end
|
||
|
|
||
3 years ago
|
it "allows filtering on a single year" do
|
||
|
expect(described_class.filter_by_years(%w[2021]).count).to eq(2)
|
||
|
end
|
||
|
|
||
|
it "allows filtering by multiple years using OR" do
|
||
|
expect(described_class.filter_by_years(%w[2021 2022]).count).to eq(3)
|
||
|
end
|
||
|
|
||
|
it "can filter by year(s) AND status" do
|
||
|
expect(described_class.filter_by_years(%w[2021 2022]).filter_by_status("completed").count).to eq(1)
|
||
|
end
|
||
3 years ago
|
|
||
|
it "filters based on date boundaries correctly" do
|
||
2 years ago
|
lettings_log_1.startdate = Time.zone.local(2022, 4, 1)
|
||
|
lettings_log_1.save!(validate: false)
|
||
|
lettings_log_2.startdate = Time.zone.local(2022, 3, 31)
|
||
|
lettings_log_2.save!(validate: false)
|
||
3 years ago
|
|
||
|
expect(described_class.filter_by_years(%w[2021]).count).to eq(1)
|
||
|
expect(described_class.filter_by_years(%w[2022]).count).to eq(2)
|
||
|
end
|
||
3 years ago
|
end
|
||
|
|
||
3 years ago
|
context "when filtering by organisation" do
|
||
|
let(:organisation_1) { FactoryBot.create(:organisation) }
|
||
|
let(:organisation_2) { FactoryBot.create(:organisation) }
|
||
|
let(:organisation_3) { FactoryBot.create(:organisation) }
|
||
|
|
||
|
before do
|
||
2 years ago
|
FactoryBot.create(:lettings_log, :in_progress, owning_organisation: organisation_1, managing_organisation: organisation_1)
|
||
|
FactoryBot.create(:lettings_log, :completed, owning_organisation: organisation_1, managing_organisation: organisation_2)
|
||
|
FactoryBot.create(:lettings_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_1)
|
||
|
FactoryBot.create(:lettings_log, :completed, owning_organisation: organisation_2, managing_organisation: organisation_2)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "filters by given organisation id" do
|
||
|
expect(described_class.filter_by_organisation([organisation_1.id]).count).to eq(3)
|
||
|
expect(described_class.filter_by_organisation([organisation_1.id, organisation_2.id]).count).to eq(4)
|
||
|
expect(described_class.filter_by_organisation([organisation_3.id]).count).to eq(0)
|
||
|
end
|
||
|
|
||
|
it "filters by given organisation" do
|
||
|
expect(described_class.filter_by_organisation([organisation_1]).count).to eq(3)
|
||
|
expect(described_class.filter_by_organisation([organisation_1, organisation_2]).count).to eq(4)
|
||
|
expect(described_class.filter_by_organisation([organisation_3]).count).to eq(0)
|
||
|
end
|
||
|
end
|
||
|
|
||
3 years ago
|
context "when filtering on status" do
|
||
|
it "allows filtering on a single status" do
|
||
|
expect(described_class.filter_by_status(%w[in_progress]).count).to eq(2)
|
||
|
end
|
||
|
|
||
|
it "allows filtering on multiple statuses" do
|
||
|
expect(described_class.filter_by_status(%w[in_progress completed]).count).to eq(3)
|
||
|
end
|
||
|
end
|
||
3 years ago
|
|
||
|
context "when filtering by user" do
|
||
|
before do
|
||
2 years ago
|
PaperTrail::Version.find_by(item_id: lettings_log_1.id, event: "create").update!(whodunnit: created_by_user.to_global_id.uri.to_s)
|
||
|
PaperTrail::Version.find_by(item_id: lettings_log_2.id, event: "create").update!(whodunnit: created_by_user.to_global_id.uri.to_s)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "allows filtering on current user" do
|
||
3 years ago
|
expect(described_class.filter_by_user(%w[yours], created_by_user).count).to eq(2)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "returns all logs when all logs selected" do
|
||
3 years ago
|
expect(described_class.filter_by_user(%w[all], created_by_user).count).to eq(3)
|
||
3 years ago
|
end
|
||
|
|
||
|
it "returns all logs when all and your users selected" do
|
||
3 years ago
|
expect(described_class.filter_by_user(%w[all yours], created_by_user).count).to eq(3)
|
||
3 years ago
|
end
|
||
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
describe "#retirement_age_for_person" do
|
||
|
context "when a person gender is Male" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.build(:lettings_log, sex1: "M") }
|
||
3 years ago
|
|
||
|
it "returns the expected retirement age" do
|
||
2 years ago
|
expect(lettings_log.retirement_age_for_person_1).to eq(67)
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
it "returns the expected plural" do
|
||
2 years ago
|
expect(lettings_log.plural_gender_for_person_1).to eq("male and non-binary people")
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when a person gender is Female" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.build(:lettings_log, sex2: "F") }
|
||
3 years ago
|
|
||
|
it "returns the expected retirement age" do
|
||
2 years ago
|
expect(lettings_log.retirement_age_for_person_2).to eq(60)
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
it "returns the expected plural" do
|
||
2 years ago
|
expect(lettings_log.plural_gender_for_person_2).to eq("females")
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when a person gender is Non-Binary" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.build(:lettings_log, sex3: "X") }
|
||
3 years ago
|
|
||
|
it "returns the expected retirement age" do
|
||
2 years ago
|
expect(lettings_log.retirement_age_for_person_3).to eq(67)
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
it "returns the expected plural" do
|
||
2 years ago
|
expect(lettings_log.plural_gender_for_person_3).to eq("male and non-binary people")
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
|
|
||
|
context "when the person gender is not set" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.build(:lettings_log) }
|
||
3 years ago
|
|
||
|
it "returns nil" do
|
||
2 years ago
|
expect(lettings_log.retirement_age_for_person_3).to be_nil
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
it "returns the expected plural" do
|
||
2 years ago
|
expect(lettings_log.plural_gender_for_person_3).to be_nil
|
||
3 years ago
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
context "when a postcode contains unicode characters" do
|
||
2 years ago
|
let(:lettings_log) { FactoryBot.build(:lettings_log, postcode_full: "SR81LS\u00A0") }
|
||
3 years ago
|
|
||
|
it "triggers a validation error" do
|
||
2 years ago
|
expect { lettings_log.save! }.to raise_error(ActiveRecord::RecordInvalid, /Enter a postcode in the correct format/)
|
||
3 years ago
|
end
|
||
|
end
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
2 years ago
|
describe "csv download" do
|
||
|
let(:scheme) { FactoryBot.create(:scheme) }
|
||
2 years ago
|
let(:location) { FactoryBot.create(:location, :export, scheme:, type_of_unit: 6, postcode: "SE11TE") }
|
||
2 years ago
|
let(:user) { FactoryBot.create(:user, organisation: location.scheme.owning_organisation) }
|
||
2 years ago
|
let(:expected_content) { csv_export_file.read }
|
||
2 years ago
|
|
||
|
before do
|
||
|
Timecop.freeze(Time.utc(2022, 6, 5))
|
||
2 years ago
|
lettings_log = FactoryBot.create(:lettings_log, needstype: 2, scheme:, location:, owning_organisation: scheme.owning_organisation, created_by: user)
|
||
|
expected_content.sub!(/\{id\}/, lettings_log["id"].to_s)
|
||
2 years ago
|
expected_content.sub!(/\{scheme_code\}/, "S#{scheme['id']}")
|
||
|
expected_content.sub!(/\{scheme_service_name\}/, scheme["service_name"].to_s)
|
||
|
expected_content.sub!(/\{scheme_sensitive\}/, scheme["sensitive"].to_s)
|
||
|
expected_content.sub!(/\{scheme_primary_client_group\}/, scheme["primary_client_group"].to_s)
|
||
|
expected_content.sub!(/\{scheme_secondary_client_group\}/, scheme["secondary_client_group"].to_s)
|
||
|
expected_content.sub!(/\{scheme_support_type\}/, scheme["support_type"].to_s)
|
||
|
expected_content.sub!(/\{scheme_intended_stay\}/, scheme["intended_stay"].to_s)
|
||
|
expected_content.sub!(/\{location_code\}/, location["id"].to_s)
|
||
|
expected_content.sub!(/\{location_startdate\}/, location["startdate"].to_s)
|
||
2 years ago
|
expected_content.sub!(/\{scheme_id\}/, scheme["service_name"].to_s)
|
||
2 years ago
|
expected_content.sub!(/\{location_id\}/, location["id"].to_s)
|
||
2 years ago
|
end
|
||
|
|
||
|
context "with a support user" do
|
||
2 years ago
|
let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download.csv", "r:UTF-8") }
|
||
2 years ago
|
|
||
2 years ago
|
it "generates a correct csv from a lettings log" do
|
||
2 years ago
|
expect(described_class.to_csv).to eq(expected_content)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "with a non support user" do
|
||
2 years ago
|
let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download_non_support.csv", "r:UTF-8") }
|
||
2 years ago
|
|
||
2 years ago
|
it "generates a correct csv from a lettings log" do
|
||
2 years ago
|
expect(described_class.to_csv(user)).to eq(expected_content)
|
||
|
end
|
||
2 years ago
|
end
|
||
|
end
|
||
3 years ago
|
end
|