Browse Source

fixup! CLDC-4145: Update tests

add 2024 derived variable tests
pull/3145/merge
Samuel Young 4 days ago
parent
commit
f1e44bbfc7
  1. 80
      spec/models/lettings_log_derived_fields_spec.rb

80
spec/models/lettings_log_derived_fields_spec.rb

@ -111,6 +111,48 @@ RSpec.describe LettingsLog, type: :model do
end end
describe "deriving household member fields" do describe "deriving household member fields" do
context "when it is 2024", metadata: { year: 24 } do
let(:startdate) { collection_start_date_for_year(2024) }
before do
log.assign_attributes(
relat2: "X",
relat3: "C",
relat4: "X",
relat5: "C",
relat7: "C",
relat8: "X",
age1: 22,
age2: 16,
age4: 60,
age6: 88,
age7: 14,
age8: 42,
)
log.set_derived_fields!
end
it "correctly derives totchild" do
expect(log.totchild).to eq 3
end
it "correctly derives totelder" do
expect(log.totelder).to eq 2
end
it "correctly derives totadult" do
expect(log.totadult).to eq 3
end
it "correctly derives economic status for tenants under 16" do
expect(log.ecstat7).to eq 9
end
end
context "when it is 2025", metadata: { year: 25 } do
let(:startdate) { collection_start_date_for_year(2025) }
before do before do
log.assign_attributes( log.assign_attributes(
relat2: "X", relat2: "X",
@ -146,9 +188,6 @@ RSpec.describe LettingsLog, type: :model do
expect(log.ecstat7).to eq 9 expect(log.ecstat7).to eq 9
end end
context "when it is 2025", metadata: { year: 25 } do
let(:startdate) { collection_start_date_for_year(2025) }
it "does not derive relationship for tenants under 16" do it "does not derive relationship for tenants under 16" do
expect(log.relat7).to be_nil expect(log.relat7).to be_nil
end end
@ -157,6 +196,41 @@ RSpec.describe LettingsLog, type: :model do
context "when it is 2026", metadata: { year: 26 } do context "when it is 2026", metadata: { year: 26 } do
let(:startdate) { collection_start_date_for_year(2026) } let(:startdate) { collection_start_date_for_year(2026) }
before do
log.assign_attributes(
relat2: "X",
relat3: "X",
relat4: "X",
relat5: "X",
# relat7 is derived
relat8: "X",
age1: 22,
age2: 16,
age4: 60,
age6: 88,
age7: 14,
age8: 42,
)
log.set_derived_fields!
end
it "correctly derives totchild" do
expect(log.totchild).to eq 1
end
it "correctly derives totelder" do
expect(log.totelder).to eq 2
end
it "correctly derives totadult" do
expect(log.totadult).to eq 3
end
it "correctly derives economic status for tenants under 16" do
expect(log.ecstat7).to eq 9
end
it "derives relationship for tenants under 16" do it "derives relationship for tenants under 16" do
expect(log.relat7).to eq "X" expect(log.relat7).to eq "X"
end end

Loading…
Cancel
Save