|
|
|
@ -1588,4 +1588,323 @@ RSpec.describe LettingsLog, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "#infer_at_most_one_relationship!" do |
|
|
|
|
|
|
|
context "when 2025", metadata: { year: 25 } do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(collection_start_date_for_year(2025)) |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.return |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when there are no existing relationships" do |
|
|
|
|
|
|
|
let(:log) { create(:lettings_log, :in_progress, hhmemb: 6, details_known_2: 0, details_known_3: 0, details_known_4: 0, details_known_5: 0, details_known_6: 0, relat2: nil, relat3: "X", relat4: "X", relat5: "R") } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when a new relationship is added" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat4 = "P" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not infer no to any relationship answers" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat2) |
|
|
|
|
|
|
|
.and not_change(log, :relat3) |
|
|
|
|
|
|
|
.and not_change(log, :relat4) |
|
|
|
|
|
|
|
.and not_change(log, :relat5) |
|
|
|
|
|
|
|
.and not_change(log, :relat6) |
|
|
|
|
|
|
|
.and not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when there is an existing relationship" do |
|
|
|
|
|
|
|
let(:log) { create(:lettings_log, :in_progress, hhmemb: 6, details_known_2: 0, details_known_3: 0, details_known_4: 0, details_known_5: 0, details_known_6: 0, relat2: "X", relat3: "P", relat4: "R", relat5: "X") } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when a new relationship is added" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat2 = "P" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not infer no to any relationship answers" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat2) |
|
|
|
|
|
|
|
.and not_change(log, :relat3) |
|
|
|
|
|
|
|
.and not_change(log, :relat4) |
|
|
|
|
|
|
|
.and not_change(log, :relat5) |
|
|
|
|
|
|
|
.and not_change(log, :relat6) |
|
|
|
|
|
|
|
.and not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when the relationship is removed" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat3 = "X" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not reset any answers" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat2) |
|
|
|
|
|
|
|
.and not_change(log, :relat3) |
|
|
|
|
|
|
|
.and not_change(log, :relat4) |
|
|
|
|
|
|
|
.and not_change(log, :relat5) |
|
|
|
|
|
|
|
.and not_change(log, :relat6) |
|
|
|
|
|
|
|
.and not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when more than one relationship is set" do |
|
|
|
|
|
|
|
let(:log) { create(:lettings_log, :in_progress, hhmemb: 6, details_known_2: 0, details_known_3: 0, details_known_4: 0, details_known_5: 0, details_known_6: 0, relat2: "X", relat3: "X", relat4: "R", relat5: "X") } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat2 = "P" |
|
|
|
|
|
|
|
log.relat3 = "P" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not infer no to any relationship answers" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat2) |
|
|
|
|
|
|
|
.and not_change(log, :relat3) |
|
|
|
|
|
|
|
.and not_change(log, :relat4) |
|
|
|
|
|
|
|
.and not_change(log, :relat5) |
|
|
|
|
|
|
|
.and not_change(log, :relat6) |
|
|
|
|
|
|
|
.and not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when 2026", metadata: { year: 26 } do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(collection_start_date_for_year(2026)) |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.return |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when there are no existing relationships" do |
|
|
|
|
|
|
|
let(:log) { create(:lettings_log, :in_progress, hhmemb: 6, details_known_2: 0, details_known_3: 0, details_known_4: 0, details_known_5: 0, details_known_6: 0, relat3: "X", relat4: "X", relat5: "R") } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when a new relationship is added" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat4 = "P" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "infers no to unanswered questions" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to change(log, :relat2).to("X") |
|
|
|
|
|
|
|
.and change(log, :relat6).to("X") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change relationship answers for people not in the household" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change relationship answers of no or prefer not to say" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat3) |
|
|
|
|
|
|
|
.and not_change(log, :relat5) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change the relationship answer for the newly added relationship" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! }.to not_change(log, :relat4) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when a 'no' is changed to 'prefers not to say'" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat4 = "R" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change any relationship answers" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat2) |
|
|
|
|
|
|
|
.and not_change(log, :relat3) |
|
|
|
|
|
|
|
.and not_change(log, :relat4) |
|
|
|
|
|
|
|
.and not_change(log, :relat5) |
|
|
|
|
|
|
|
.and not_change(log, :relat6) |
|
|
|
|
|
|
|
.and not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when a 'prefers not to say' is changed to 'no'" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat5 = "X" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change any relationship answers" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat2) |
|
|
|
|
|
|
|
.and not_change(log, :relat3) |
|
|
|
|
|
|
|
.and not_change(log, :relat4) |
|
|
|
|
|
|
|
.and not_change(log, :relat5) |
|
|
|
|
|
|
|
.and not_change(log, :relat6) |
|
|
|
|
|
|
|
.and not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when there is an existing relationship" do |
|
|
|
|
|
|
|
let(:log) { create(:lettings_log, :in_progress, hhmemb: 6, details_known_2: 0, details_known_3: 0, details_known_4: 0, details_known_5: 0, details_known_6: 0, relat2: "X", relat3: "P", relat4: "R", relat5: "X") } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "and a new relationship is added to an earlier person than the existing one" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat6 = nil # This is necessary because `log.set_derived_fields!` runs when the log is created from the factory, which sets `relat6` to "X". |
|
|
|
|
|
|
|
log.relat2 = "P" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "infers no to the existing relationship" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! }.to change(log, :relat3).to "X" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "infers no to unanswered questions" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! }.to change(log, :relat6).to "X" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change relationship answers for people not in the household" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change relationship answers of no or prefer not to say" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat5) |
|
|
|
|
|
|
|
.and not_change(log, :relat4) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change the relationship answer for the newly added relationship" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! }.to not_change(log, :relat2) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "and a new relationship is added to an later person than the existing one" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat6 = nil # This is necessary because `log.set_derived_fields!` runs when the log is created from the factory, which sets `relat6` to "X". |
|
|
|
|
|
|
|
log.relat5 = "P" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "infers no to the existing relationship" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! }.to change(log, :relat3).to "X" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "infers no to unanswered questions" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! }.to change(log, :relat6).to "X" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change relationship answers for people not in the household" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change relationship answers of no or prefer not to say" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat2) |
|
|
|
|
|
|
|
.and not_change(log, :relat4) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change the relationship answer for the newly added relationship" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! }.to not_change(log, :relat5) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when a 'no' is changed to 'prefers not to say'" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat4 = "R" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change any relationship answers" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat2) |
|
|
|
|
|
|
|
.and not_change(log, :relat3) |
|
|
|
|
|
|
|
.and not_change(log, :relat4) |
|
|
|
|
|
|
|
.and not_change(log, :relat5) |
|
|
|
|
|
|
|
.and not_change(log, :relat6) |
|
|
|
|
|
|
|
.and not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when a 'prefers not to say' is changed to 'no'" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat5 = "X" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change any relationship answers" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat2) |
|
|
|
|
|
|
|
.and not_change(log, :relat3) |
|
|
|
|
|
|
|
.and not_change(log, :relat4) |
|
|
|
|
|
|
|
.and not_change(log, :relat5) |
|
|
|
|
|
|
|
.and not_change(log, :relat6) |
|
|
|
|
|
|
|
.and not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "and the relationship is removed" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat3 = "X" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not reset any answers" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat2) |
|
|
|
|
|
|
|
.and not_change(log, :relat3) |
|
|
|
|
|
|
|
.and not_change(log, :relat4) |
|
|
|
|
|
|
|
.and not_change(log, :relat5) |
|
|
|
|
|
|
|
.and not_change(log, :relat6) |
|
|
|
|
|
|
|
.and not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when more than one relationship is set" do |
|
|
|
|
|
|
|
let(:log) { create(:lettings_log, :in_progress, hhmemb: 6, details_known_2: 0, details_known_3: 0, details_known_4: 0, details_known_5: 0, details_known_6: 0, relat2: "X", relat3: "X", relat4: "R", relat5: "X") } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
log.relat2 = "P" |
|
|
|
|
|
|
|
log.relat3 = "P" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "keeps the lower numbered relationship and infers the higher numbered one to false" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat2) |
|
|
|
|
|
|
|
.and change(log, :relat3).to("X") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "infers no to unanswered questions" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! }.to change(log, :relat6).to "X" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change relationship answers for people not in the household" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat7) |
|
|
|
|
|
|
|
.and not_change(log, :relat8) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not change relationship answers of no or prefer not to say" do |
|
|
|
|
|
|
|
expect { log.set_derived_fields! } |
|
|
|
|
|
|
|
.to not_change(log, :relat5) |
|
|
|
|
|
|
|
.and not_change(log, :relat4) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|