|
|
@ -1,9 +1,10 @@ |
|
|
|
require "rails_helper" |
|
|
|
require "rails_helper" |
|
|
|
require_relative "../request_helper" |
|
|
|
require_relative "../request_helper" |
|
|
|
|
|
|
|
|
|
|
|
RSpec.describe Form, type: :model do |
|
|
|
RSpec.describe CaseLog do |
|
|
|
let(:owning_organisation) { FactoryBot.create(:organisation) } |
|
|
|
let(:owning_organisation) { FactoryBot.create(:organisation) } |
|
|
|
let(:managing_organisation) { owning_organisation } |
|
|
|
let(:managing_organisation) { owning_organisation } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
RequestHelper.stub_http_requests |
|
|
|
RequestHelper.stub_http_requests |
|
|
|
end |
|
|
|
end |
|
|
@ -12,6 +13,7 @@ RSpec.describe Form, type: :model do |
|
|
|
let(:case_log) { FactoryBot.build(:case_log) } |
|
|
|
let(:case_log) { FactoryBot.build(:case_log) } |
|
|
|
let(:case_log_2) { FactoryBot.build(:case_log, startdate: Time.zone.local(2022, 1, 1)) } |
|
|
|
let(:case_log_2) { FactoryBot.build(:case_log, startdate: Time.zone.local(2022, 1, 1)) } |
|
|
|
let(:case_log_year_2) { FactoryBot.build(:case_log, startdate: Time.zone.local(2023, 5, 1)) } |
|
|
|
let(:case_log_year_2) { FactoryBot.build(:case_log, startdate: Time.zone.local(2023, 5, 1)) } |
|
|
|
|
|
|
|
|
|
|
|
it "has returns the correct form based on the start date" do |
|
|
|
it "has returns the correct form based on the start date" do |
|
|
|
expect(case_log.form_name).to eq("2021_2022") |
|
|
|
expect(case_log.form_name).to eq("2021_2022") |
|
|
|
expect(case_log_2.form_name).to eq("2021_2022") |
|
|
|
expect(case_log_2.form_name).to eq("2021_2022") |
|
|
@ -21,16 +23,36 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
describe "#new" do |
|
|
|
describe "#new" do |
|
|
|
|
|
|
|
it "raises an error when offered is present and invalid" do |
|
|
|
|
|
|
|
expect { |
|
|
|
|
|
|
|
described_class.create!( |
|
|
|
|
|
|
|
offered: "random", |
|
|
|
|
|
|
|
owning_organisation: owning_organisation, |
|
|
|
|
|
|
|
managing_organisation: managing_organisation, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "raises an error when previous_postcode is present and invalid" do |
|
|
|
|
|
|
|
expect { |
|
|
|
|
|
|
|
described_class.create!( |
|
|
|
|
|
|
|
previous_postcode: "invalid_postcode", |
|
|
|
|
|
|
|
owning_organisation: owning_organisation, |
|
|
|
|
|
|
|
managing_organisation: managing_organisation, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "validates age is a number" do |
|
|
|
it "validates age is a number" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age1: "random", |
|
|
|
age1: "random", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation, |
|
|
|
managing_organisation: managing_organisation, |
|
|
|
) |
|
|
|
) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age3: "random", |
|
|
|
age3: "random", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation, |
|
|
|
managing_organisation: managing_organisation, |
|
|
@ -40,14 +62,14 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "validates age is under 120" do |
|
|
|
it "validates age is under 120" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age1: 121, |
|
|
|
age1: 121, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation, |
|
|
|
managing_organisation: managing_organisation, |
|
|
|
) |
|
|
|
) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age3: 121, |
|
|
|
age3: 121, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation, |
|
|
|
managing_organisation: managing_organisation, |
|
|
@ -57,14 +79,14 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "validates age is over 0" do |
|
|
|
it "validates age is over 0" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age1: 0, |
|
|
|
age1: 0, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation, |
|
|
|
managing_organisation: managing_organisation, |
|
|
|
) |
|
|
|
) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age3: 0, |
|
|
|
age3: 0, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation, |
|
|
|
managing_organisation: managing_organisation, |
|
|
@ -72,10 +94,10 @@ RSpec.describe Form, type: :model do |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "reasonable preference is yes" do |
|
|
|
context "when a reasonable preference is set to yes" do |
|
|
|
it "validates that previously homeless should be selected" do |
|
|
|
it "validates that previously homeless should be selected" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
homeless: "No", |
|
|
|
homeless: "No", |
|
|
|
reasonpref: "Yes", |
|
|
|
reasonpref: "Yes", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -85,10 +107,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "reasonable preference is no" do |
|
|
|
context "when a reasonable preference is set to no" do |
|
|
|
it "validates no reason is needed" do |
|
|
|
it "validates no reason is needed" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
reasonpref: "No", |
|
|
|
reasonpref: "No", |
|
|
|
rp_homeless: "No", |
|
|
|
rp_homeless: "No", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -99,7 +121,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "validates that no reason has been provided" do |
|
|
|
it "validates that no reason has been provided" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
reasonpref: "No", |
|
|
|
reasonpref: "No", |
|
|
|
rp_medwel: "Yes", |
|
|
|
rp_medwel: "Yes", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -109,20 +131,21 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "reason for leaving last settled home validation" do |
|
|
|
context "with a reason for leaving last settled home validation" do |
|
|
|
it "Reason for leaving must be don’t know if reason for leaving settled home (Q9a) is don’t know." do |
|
|
|
it "checks the reason for leaving must be don’t know if reason for leaving settled home (Q9a) is don’t know." do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(reason: "Don’t know", |
|
|
|
described_class.create!(reason: "Don’t know", |
|
|
|
underoccupation_benefitcap: "Yes - benefit cap", |
|
|
|
underoccupation_benefitcap: "Yes - benefit cap", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
context "other reason for leaving last settled home validation" do |
|
|
|
|
|
|
|
|
|
|
|
context "with reason for leaving last settled home validation set to other" do |
|
|
|
it "must be provided if main reason for leaving last settled home was given as other" do |
|
|
|
it "must be provided if main reason for leaving last settled home was given as other" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(reason: "Other", |
|
|
|
described_class.create!(reason: "Other", |
|
|
|
other_reason_for_leaving_last_settled_home: nil, |
|
|
|
other_reason_for_leaving_last_settled_home: nil, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -131,7 +154,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "must not be provided if the main reason for leaving settled home is not other" do |
|
|
|
it "must not be provided if the main reason for leaving settled home is not other" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(reason: "Repossession", |
|
|
|
described_class.create!(reason: "Repossession", |
|
|
|
other_reason_for_leaving_last_settled_home: "the other reason provided", |
|
|
|
other_reason_for_leaving_last_settled_home: "the other reason provided", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -139,10 +162,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "armed forces injured validation" do |
|
|
|
context "with armed forces injured validation" do |
|
|
|
it "must not be answered if tenant was not a regular or reserve in armed forces" do |
|
|
|
it "must not be answered if tenant was not a regular or reserve in armed forces" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(armedforces: "No", |
|
|
|
described_class.create!(armedforces: "No", |
|
|
|
reservist: "Yes", |
|
|
|
reservist: "Yes", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -150,10 +173,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "Validate pregnancy questions" do |
|
|
|
context "when validating pregnancy questions" do |
|
|
|
it "Cannot answer yes if no female tenants" do |
|
|
|
it "Cannot answer yes if no female tenants" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(preg_occ: "Yes", |
|
|
|
described_class.create!(preg_occ: "Yes", |
|
|
|
sex1: "Male", |
|
|
|
sex1: "Male", |
|
|
|
age1: 20, |
|
|
|
age1: 20, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -163,7 +186,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "Cannot answer yes if no female tenants within age range" do |
|
|
|
it "Cannot answer yes if no female tenants within age range" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(preg_occ: "Yes", |
|
|
|
described_class.create!(preg_occ: "Yes", |
|
|
|
sex1: "Female", |
|
|
|
sex1: "Female", |
|
|
|
age1: 51, |
|
|
|
age1: 51, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -173,7 +196,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "Cannot answer prefer not to say if no valid tenants" do |
|
|
|
it "Cannot answer prefer not to say if no valid tenants" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(preg_occ: "Prefer not to say", |
|
|
|
described_class.create!(preg_occ: "Prefer not to say", |
|
|
|
sex1: "Male", |
|
|
|
sex1: "Male", |
|
|
|
age1: 20, |
|
|
|
age1: 20, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -183,7 +206,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "Can answer yes if valid tenants" do |
|
|
|
it "Can answer yes if valid tenants" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(preg_occ: "Yes", |
|
|
|
described_class.create!(preg_occ: "Yes", |
|
|
|
sex1: "Female", |
|
|
|
sex1: "Female", |
|
|
|
age1: 20, |
|
|
|
age1: 20, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -193,7 +216,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "Can answer yes if valid second tenant" do |
|
|
|
it "Can answer yes if valid second tenant" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(preg_occ: "Yes", |
|
|
|
described_class.create!(preg_occ: "Yes", |
|
|
|
sex1: "Male", age1: 99, |
|
|
|
sex1: "Male", age1: 99, |
|
|
|
sex2: "Female", |
|
|
|
sex2: "Female", |
|
|
|
age2: 20, |
|
|
|
age2: 20, |
|
|
@ -203,10 +226,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "Property vacancy and let as validations" do |
|
|
|
context "when validating property vacancy and let as" do |
|
|
|
it "cannot have a previously let as type, if it hasn't been let before" do |
|
|
|
it "cannot have a previously let as type, if it hasn't been let before" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
first_time_property_let_as_social_housing: "No", |
|
|
|
first_time_property_let_as_social_housing: "No", |
|
|
|
unitletas: "Social rent basis", |
|
|
|
unitletas: "Social rent basis", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -214,7 +237,7 @@ RSpec.describe Form, type: :model do |
|
|
|
) |
|
|
|
) |
|
|
|
}.not_to raise_error |
|
|
|
}.not_to raise_error |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
unitletas: "Social rent basis", |
|
|
|
unitletas: "Social rent basis", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -222,7 +245,7 @@ RSpec.describe Form, type: :model do |
|
|
|
) |
|
|
|
) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
unitletas: "Affordable rent basis", |
|
|
|
unitletas: "Affordable rent basis", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -230,7 +253,7 @@ RSpec.describe Form, type: :model do |
|
|
|
) |
|
|
|
) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
unitletas: "Intermediate rent basis", |
|
|
|
unitletas: "Intermediate rent basis", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -238,7 +261,7 @@ RSpec.describe Form, type: :model do |
|
|
|
) |
|
|
|
) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
unitletas: "Don’t know", |
|
|
|
unitletas: "Don’t know", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -249,7 +272,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "must have a first let reason for vacancy if it's being let as social housing for the first time" do |
|
|
|
it "must have a first let reason for vacancy if it's being let as social housing for the first time" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
rsnvac: "First let of new-build property", |
|
|
|
rsnvac: "First let of new-build property", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -257,7 +280,7 @@ RSpec.describe Form, type: :model do |
|
|
|
) |
|
|
|
) |
|
|
|
}.not_to raise_error |
|
|
|
}.not_to raise_error |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
rsnvac: "First let of conversion, rehabilitation or acquired property", |
|
|
|
rsnvac: "First let of conversion, rehabilitation or acquired property", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -265,7 +288,7 @@ RSpec.describe Form, type: :model do |
|
|
|
) |
|
|
|
) |
|
|
|
}.not_to raise_error |
|
|
|
}.not_to raise_error |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
rsnvac: "First let of leased property", |
|
|
|
rsnvac: "First let of leased property", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -273,7 +296,7 @@ RSpec.describe Form, type: :model do |
|
|
|
) |
|
|
|
) |
|
|
|
}.not_to raise_error |
|
|
|
}.not_to raise_error |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
first_time_property_let_as_social_housing: "Yes", |
|
|
|
rsnvac: "Tenant moved to care home", |
|
|
|
rsnvac: "Tenant moved to care home", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -283,19 +306,19 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "Shared accomodation bedrooms validation" do |
|
|
|
context "when validating shared accommodation bedrooms" do |
|
|
|
it "you must have more than zero bedrooms" do |
|
|
|
it "checks you must have more than zero bedrooms" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(unittype_gn: "Shared house", |
|
|
|
described_class.create!(unittype_gn: "Shared house", |
|
|
|
beds: 0, |
|
|
|
beds: 0, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "you must answer less than 8 bedrooms" do |
|
|
|
it "checks you must answer less than 8 bedrooms" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(unittype_gn: "Shared bungalow", |
|
|
|
described_class.create!(unittype_gn: "Shared bungalow", |
|
|
|
beds: 8, |
|
|
|
beds: 8, |
|
|
|
other_hhmemb: 1, |
|
|
|
other_hhmemb: 1, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -303,9 +326,9 @@ RSpec.describe Form, type: :model do |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "you must answer less than 8 bedrooms" do |
|
|
|
it "checks you must answer less than 4 bedrooms" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(unittype_gn: "Shared bungalow", |
|
|
|
described_class.create!(unittype_gn: "Shared bungalow", |
|
|
|
beds: 4, |
|
|
|
beds: 4, |
|
|
|
other_hhmemb: 0, |
|
|
|
other_hhmemb: 0, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -313,18 +336,18 @@ RSpec.describe Form, type: :model do |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "A bedsit must only have one room" do |
|
|
|
it "checks a bedsit cannot have more than one room" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(unittype_gn: "Bedsit", |
|
|
|
described_class.create!(unittype_gn: "Bedsit", |
|
|
|
beds: 2, |
|
|
|
beds: 2, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "A bedsit must only have one room" do |
|
|
|
it "checks a bedsit cannot be less than one room" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(unittype_gn: "Bedsit", |
|
|
|
described_class.create!(unittype_gn: "Bedsit", |
|
|
|
beds: 0, |
|
|
|
beds: 0, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -332,10 +355,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "outstanding rent or charges validation" do |
|
|
|
context "when validating outstanding rent or charges" do |
|
|
|
it "must be not be anwered if answered no to outstanding rent or charges" do |
|
|
|
it "must be not be anwered if answered no to outstanding rent or charges" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(hbrentshortfall: "No", |
|
|
|
described_class.create!(hbrentshortfall: "No", |
|
|
|
tshortfall: 99, |
|
|
|
tshortfall: 99, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -343,10 +366,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "tenant’s income is from Universal Credit, state pensions or benefits" do |
|
|
|
context "with tenant’s income from Universal Credit, state pensions or benefits" do |
|
|
|
it "Cannot be All if person 1 works full time" do |
|
|
|
it "Cannot be All if person 1 works full time" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
benefits: "All", |
|
|
|
benefits: "All", |
|
|
|
ecstat1: "Full-time - 30 hours or more", |
|
|
|
ecstat1: "Full-time - 30 hours or more", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -357,7 +380,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "Cannot be All if person 1 works part time" do |
|
|
|
it "Cannot be All if person 1 works part time" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
benefits: "All", |
|
|
|
benefits: "All", |
|
|
|
ecstat1: "Part-time - Less than 30 hours", |
|
|
|
ecstat1: "Part-time - Less than 30 hours", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -368,7 +391,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "Cannot be 1 All if any of persons 2-4 are person 1's partner and work part or full time" do |
|
|
|
it "Cannot be 1 All if any of persons 2-4 are person 1's partner and work part or full time" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
benefits: "All", |
|
|
|
benefits: "All", |
|
|
|
relat2: "Partner", |
|
|
|
relat2: "Partner", |
|
|
|
ecstat2: "Part-time - Less than 30 hours", |
|
|
|
ecstat2: "Part-time - Less than 30 hours", |
|
|
@ -379,10 +402,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "fixed term tenancy length" do |
|
|
|
context "when validaiting fixed term tenancy" do |
|
|
|
it "Must not be completed if Type of main tenancy is not responded with either Secure or Assured shorthold " do |
|
|
|
it "Must not be completed if Type of main tenancy is not responded with either Secure or Assured shorthold " do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(tenancy: "Other", |
|
|
|
described_class.create!(tenancy: "Other", |
|
|
|
tenancylength: 10, |
|
|
|
tenancylength: 10, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -391,21 +414,21 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "Must be completed and between 2 and 99 if type of tenancy is Assured shorthold" do |
|
|
|
it "Must be completed and between 2 and 99 if type of tenancy is Assured shorthold" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(tenancy: "Assured Shorthold", |
|
|
|
described_class.create!(tenancy: "Assured Shorthold", |
|
|
|
tenancylength: 1, |
|
|
|
tenancylength: 1, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(tenancy: "Assured Shorthold", |
|
|
|
described_class.create!(tenancy: "Assured Shorthold", |
|
|
|
tenancylength: nil, |
|
|
|
tenancylength: nil, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(tenancy: "Assured Shorthold", |
|
|
|
described_class.create!(tenancy: "Assured Shorthold", |
|
|
|
tenancylength: 2, |
|
|
|
tenancylength: 2, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -414,28 +437,28 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "Must be empty or between 2 and 99 if type of tenancy is Secure" do |
|
|
|
it "Must be empty or between 2 and 99 if type of tenancy is Secure" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(tenancy: "Secure (including flexible)", |
|
|
|
described_class.create!(tenancy: "Secure (including flexible)", |
|
|
|
tenancylength: 1, |
|
|
|
tenancylength: 1, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(tenancy: "Secure (including flexible)", |
|
|
|
described_class.create!(tenancy: "Secure (including flexible)", |
|
|
|
tenancylength: 100, |
|
|
|
tenancylength: 100, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(tenancy: "Secure (including flexible)", |
|
|
|
described_class.create!(tenancy: "Secure (including flexible)", |
|
|
|
tenancylength: nil, |
|
|
|
tenancylength: nil, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.not_to raise_error |
|
|
|
}.not_to raise_error |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(tenancy: "Secure (including flexible)", |
|
|
|
described_class.create!(tenancy: "Secure (including flexible)", |
|
|
|
tenancylength: 2, |
|
|
|
tenancylength: 2, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -443,10 +466,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "armed forces active validation" do |
|
|
|
context "when validating armed forces is active" do |
|
|
|
it "must not be answered if not ever served as a regular" do |
|
|
|
it "must not be answered if not ever served as a regular" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(armedforces: "No", |
|
|
|
described_class.create!(armedforces: "No", |
|
|
|
leftreg: "Yes", |
|
|
|
leftreg: "Yes", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -455,20 +478,20 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
# Crossover over tests here as injured must be answered as well for no error |
|
|
|
# Crossover over tests here as injured must be answered as well for no error |
|
|
|
it "must be answered if ever served in the forces as a regular" do |
|
|
|
it "must be answered if ever served in the forces as a regular" do |
|
|
|
expect do |
|
|
|
expect { |
|
|
|
CaseLog.create!(armedforces: "A current or former regular in the UK Armed Forces (excluding National Service)", |
|
|
|
described_class.create!(armedforces: "A current or former regular in the UK Armed Forces (excluding National Service)", |
|
|
|
leftreg: "Yes", |
|
|
|
leftreg: "Yes", |
|
|
|
reservist: "Yes", |
|
|
|
reservist: "Yes", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
end |
|
|
|
}.not_to raise_error |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "household_member_validations" do |
|
|
|
context "when validating household members" do |
|
|
|
it "validate that persons aged under 16 must have relationship Child" do |
|
|
|
it "validate that persons aged under 16 must have relationship Child" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age2: 14, |
|
|
|
age2: 14, |
|
|
|
relat2: "Partner", |
|
|
|
relat2: "Partner", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -479,7 +502,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "validate that persons aged over 70 must be retired" do |
|
|
|
it "validate that persons aged over 70 must be retired" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age2: 71, |
|
|
|
age2: 71, |
|
|
|
ecstat2: "Full-time - 30 hours or more", |
|
|
|
ecstat2: "Full-time - 30 hours or more", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -490,7 +513,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "validate that a male, retired persons must be over 65" do |
|
|
|
it "validate that a male, retired persons must be over 65" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age2: 64, |
|
|
|
age2: 64, |
|
|
|
sex2: "Male", |
|
|
|
sex2: "Male", |
|
|
|
ecstat2: "Retired", |
|
|
|
ecstat2: "Retired", |
|
|
@ -502,7 +525,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "validate that a female, retired persons must be over 60" do |
|
|
|
it "validate that a female, retired persons must be over 60" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age2: 59, |
|
|
|
age2: 59, |
|
|
|
sex2: "Female", |
|
|
|
sex2: "Female", |
|
|
|
ecstat2: "Retired", |
|
|
|
ecstat2: "Retired", |
|
|
@ -514,7 +537,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "validate that persons aged under 16 must be a child (economically speaking)" do |
|
|
|
it "validate that persons aged under 16 must be a child (economically speaking)" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age2: 15, |
|
|
|
age2: 15, |
|
|
|
ecstat2: "Full-time - 30 hours or more", |
|
|
|
ecstat2: "Full-time - 30 hours or more", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -525,7 +548,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "validate that persons aged between 16 and 19 that are a child must be a full time student or economic status refused" do |
|
|
|
it "validate that persons aged between 16 and 19 that are a child must be a full time student or economic status refused" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age2: 17, |
|
|
|
age2: 17, |
|
|
|
relat2: "Child - includes young adult and grown-up", |
|
|
|
relat2: "Child - includes young adult and grown-up", |
|
|
|
ecstat2: "Full-time - 30 hours or more", |
|
|
|
ecstat2: "Full-time - 30 hours or more", |
|
|
@ -537,7 +560,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "validate that persons aged under 16 must be a child relationship" do |
|
|
|
it "validate that persons aged under 16 must be a child relationship" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
age2: 15, |
|
|
|
age2: 15, |
|
|
|
relat2: "Partner", |
|
|
|
relat2: "Partner", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -548,7 +571,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "validate that no more than 1 partner relationship exists" do |
|
|
|
it "validate that no more than 1 partner relationship exists" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
relat2: "Partner", |
|
|
|
relat2: "Partner", |
|
|
|
relat3: "Partner", |
|
|
|
relat3: "Partner", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -558,17 +581,17 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "other tenancy type validation" do |
|
|
|
context "when validating other tenancy type" do |
|
|
|
it "must be provided if tenancy type was given as other" do |
|
|
|
it "must be provided if tenancy type was given as other" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(tenancy: "Other", |
|
|
|
described_class.create!(tenancy: "Other", |
|
|
|
tenancyother: nil, |
|
|
|
tenancyother: nil, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(tenancy: "Other", |
|
|
|
described_class.create!(tenancy: "Other", |
|
|
|
tenancyother: "type", |
|
|
|
tenancyother: "type", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -577,14 +600,14 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "must not be provided if tenancy type is not other" do |
|
|
|
it "must not be provided if tenancy type is not other" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(tenancy: "Secure (including flexible)", |
|
|
|
described_class.create!(tenancy: "Secure (including flexible)", |
|
|
|
tenancyother: "the other reason provided", |
|
|
|
tenancyother: "the other reason provided", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(tenancy: "Secure (including flexible)", |
|
|
|
described_class.create!(tenancy: "Secure (including flexible)", |
|
|
|
tenancyother: nil, |
|
|
|
tenancyother: nil, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -592,10 +615,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "income ranges" do |
|
|
|
context "when saving income ranges" do |
|
|
|
it "validates net income maximum" do |
|
|
|
it "validates net income maximum" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
ecstat1: "Full-time - 30 hours or more", |
|
|
|
ecstat1: "Full-time - 30 hours or more", |
|
|
|
earnings: 5000, |
|
|
|
earnings: 5000, |
|
|
|
incfreq: "Weekly", |
|
|
|
incfreq: "Weekly", |
|
|
@ -607,7 +630,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "validates net income minimum" do |
|
|
|
it "validates net income minimum" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
ecstat1: "Full-time - 30 hours or more", |
|
|
|
ecstat1: "Full-time - 30 hours or more", |
|
|
|
earnings: 1, |
|
|
|
earnings: 1, |
|
|
|
incfreq: "Weekly", |
|
|
|
incfreq: "Weekly", |
|
|
@ -617,7 +640,7 @@ RSpec.describe Form, type: :model do |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "given an income in upper soft validation range" do |
|
|
|
context "with an income in upper soft range" do |
|
|
|
let(:case_log) do |
|
|
|
let(:case_log) do |
|
|
|
FactoryBot.create(:case_log, |
|
|
|
FactoryBot.create(:case_log, |
|
|
|
ecstat1: "Full-time - 30 hours or more", |
|
|
|
ecstat1: "Full-time - 30 hours or more", |
|
|
@ -632,7 +655,7 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "given an income in lower soft validation range" do |
|
|
|
context "with an income in lower soft validation range" do |
|
|
|
let(:case_log) do |
|
|
|
let(:case_log) do |
|
|
|
FactoryBot.create(:case_log, |
|
|
|
FactoryBot.create(:case_log, |
|
|
|
ecstat1: "Full-time - 30 hours or more", |
|
|
|
ecstat1: "Full-time - 30 hours or more", |
|
|
@ -648,10 +671,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "major repairs date" do |
|
|
|
context "when validating major repairs date" do |
|
|
|
it "cannot be later than the tenancy start date" do |
|
|
|
it "cannot be later than the tenancy start date" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
mrcdate: Date.new(2021, 10, 10), |
|
|
|
mrcdate: Date.new(2021, 10, 10), |
|
|
|
startdate: Date.new(2021, 10, 9), |
|
|
|
startdate: Date.new(2021, 10, 9), |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -660,7 +683,7 @@ RSpec.describe Form, type: :model do |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
mrcdate: Date.new(2021, 10, 9), |
|
|
|
mrcdate: Date.new(2021, 10, 9), |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -671,7 +694,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "must not be completed if reason for vacancy is first let" do |
|
|
|
it "must not be completed if reason for vacancy is first let" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
mrcdate: Date.new(2020, 10, 10), |
|
|
|
mrcdate: Date.new(2020, 10, 10), |
|
|
|
rsnvac: "First let of new-build property", |
|
|
|
rsnvac: "First let of new-build property", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -680,7 +703,7 @@ RSpec.describe Form, type: :model do |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
mrcdate: Date.new(2020, 10, 10), |
|
|
|
mrcdate: Date.new(2020, 10, 10), |
|
|
|
rsnvac: "First let of conversion, rehabilitation or acquired property", |
|
|
|
rsnvac: "First let of conversion, rehabilitation or acquired property", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -689,7 +712,7 @@ RSpec.describe Form, type: :model do |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
mrcdate: Date.new(2020, 10, 10), |
|
|
|
mrcdate: Date.new(2020, 10, 10), |
|
|
|
rsnvac: "First let of leased property", |
|
|
|
rsnvac: "First let of leased property", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -700,7 +723,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "must have less than two years between the tenancy start date and major repairs date" do |
|
|
|
it "must have less than two years between the tenancy start date and major repairs date" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
mrcdate: Date.new(2017, 10, 10), |
|
|
|
mrcdate: Date.new(2017, 10, 10), |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -710,10 +733,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "void date" do |
|
|
|
context "when saving void date" do |
|
|
|
it "must have less than 10 years between the tenancy start date and void" do |
|
|
|
it "must have less than 10 years between the tenancy start date and void" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
property_void_date: Date.new(2009, 10, 10), |
|
|
|
property_void_date: Date.new(2009, 10, 10), |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -722,7 +745,7 @@ RSpec.describe Form, type: :model do |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
property_void_date: Date.new(2015, 10, 10), |
|
|
|
property_void_date: Date.new(2015, 10, 10), |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -733,7 +756,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "must be before the tenancy start date" do |
|
|
|
it "must be before the tenancy start date" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
property_void_date: Date.new(2021, 10, 11), |
|
|
|
property_void_date: Date.new(2021, 10, 11), |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -742,7 +765,7 @@ RSpec.describe Form, type: :model do |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
property_void_date: Date.new(2019, 10, 10), |
|
|
|
property_void_date: Date.new(2019, 10, 10), |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -753,7 +776,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "must be before major repairs date if major repairs date provided" do |
|
|
|
it "must be before major repairs date if major repairs date provided" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!( |
|
|
|
described_class.create!( |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
startdate: Date.new(2021, 10, 10), |
|
|
|
mrcdate: Date.new(2019, 10, 10), |
|
|
|
mrcdate: Date.new(2019, 10, 10), |
|
|
|
property_void_date: Date.new(2019, 11, 11), |
|
|
|
property_void_date: Date.new(2019, 11, 11), |
|
|
@ -764,70 +787,17 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "Validate pregnancy questions" do |
|
|
|
context "when validating type of unit" do |
|
|
|
it "Cannot answer yes if no female tenants" do |
|
|
|
|
|
|
|
expect { |
|
|
|
|
|
|
|
CaseLog.create!(preg_occ: "Yes", |
|
|
|
|
|
|
|
sex1: "Male", |
|
|
|
|
|
|
|
age1: 20, |
|
|
|
|
|
|
|
owning_organisation: owning_organisation, |
|
|
|
|
|
|
|
managing_organisation: managing_organisation) |
|
|
|
|
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "Cannot answer yes if no female tenants within age range" do |
|
|
|
|
|
|
|
expect { |
|
|
|
|
|
|
|
CaseLog.create!(preg_occ: "Yes", |
|
|
|
|
|
|
|
sex1: "Female", |
|
|
|
|
|
|
|
age1: 51, |
|
|
|
|
|
|
|
owning_organisation: owning_organisation, |
|
|
|
|
|
|
|
managing_organisation: managing_organisation) |
|
|
|
|
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "Cannot answer prefer not to say if no valid tenants" do |
|
|
|
|
|
|
|
expect { |
|
|
|
|
|
|
|
CaseLog.create!(preg_occ: "Prefer not to say", |
|
|
|
|
|
|
|
sex1: "Male", |
|
|
|
|
|
|
|
age1: 20, |
|
|
|
|
|
|
|
owning_organisation: owning_organisation, |
|
|
|
|
|
|
|
managing_organisation: managing_organisation) |
|
|
|
|
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "Can answer yes if valid tenants" do |
|
|
|
|
|
|
|
expect { |
|
|
|
|
|
|
|
CaseLog.create!(preg_occ: "Yes", |
|
|
|
|
|
|
|
sex1: "Female", |
|
|
|
|
|
|
|
age1: 20, |
|
|
|
|
|
|
|
owning_organisation: owning_organisation, |
|
|
|
|
|
|
|
managing_organisation: managing_organisation) |
|
|
|
|
|
|
|
}.not_to raise_error |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "Can answer yes if valid second tenant" do |
|
|
|
|
|
|
|
expect { |
|
|
|
|
|
|
|
CaseLog.create!(preg_occ: "Yes", |
|
|
|
|
|
|
|
sex1: "Male", age1: 99, |
|
|
|
|
|
|
|
sex2: "Female", |
|
|
|
|
|
|
|
age2: 20, |
|
|
|
|
|
|
|
owning_organisation: owning_organisation, |
|
|
|
|
|
|
|
managing_organisation: managing_organisation) |
|
|
|
|
|
|
|
}.not_to raise_error |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "Validate type of unit" do |
|
|
|
|
|
|
|
it "Cannot be bedsit if no of bedrooms is greater than 1" do |
|
|
|
it "Cannot be bedsit if no of bedrooms is greater than 1" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(unittype_gn: "Bedsit", |
|
|
|
described_class.create!(unittype_gn: "Bedsit", |
|
|
|
beds: 2, |
|
|
|
beds: 2, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(unittype_gn: "Bedsit", |
|
|
|
described_class.create!(unittype_gn: "Bedsit", |
|
|
|
beds: 1, |
|
|
|
beds: 1, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -835,17 +805,17 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "Validate local authority" do |
|
|
|
context "when validating local authority" do |
|
|
|
it "Has to be london if rent type london affordable rent" do |
|
|
|
it "Has to be london if rent type london affordable rent" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(la: "Ashford", |
|
|
|
described_class.create!(la: "Ashford", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(la: "Westminster", |
|
|
|
described_class.create!(la: "Westminster", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -853,10 +823,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "For accessibility requirements" do |
|
|
|
context "with accessibility requirements" do |
|
|
|
it "validates that only one option can be selected" do |
|
|
|
it "validates that only one option can be selected" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(housingneeds_a: "Yes", |
|
|
|
described_class.create!(housingneeds_a: "Yes", |
|
|
|
housingneeds_b: "Yes", |
|
|
|
housingneeds_b: "Yes", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -866,31 +836,31 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
it "validates that only one option a, b, or c can be selected in conjunction with f" do |
|
|
|
it "validates that only one option a, b, or c can be selected in conjunction with f" do |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(housingneeds_a: "Yes", |
|
|
|
described_class.create!(housingneeds_a: "Yes", |
|
|
|
housingneeds_f: "Yes", |
|
|
|
housingneeds_f: "Yes", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to_not raise_error |
|
|
|
}.not_to raise_error |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(housingneeds_b: "Yes", |
|
|
|
described_class.create!(housingneeds_b: "Yes", |
|
|
|
housingneeds_f: "Yes", |
|
|
|
housingneeds_f: "Yes", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to_not raise_error |
|
|
|
}.not_to raise_error |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(housingneeds_c: "Yes", |
|
|
|
described_class.create!(housingneeds_c: "Yes", |
|
|
|
housingneeds_f: "Yes", |
|
|
|
housingneeds_f: "Yes", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
}.to_not raise_error |
|
|
|
}.not_to raise_error |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(housingneeds_g: "Yes", |
|
|
|
described_class.create!(housingneeds_g: "Yes", |
|
|
|
housingneeds_f: "Yes", |
|
|
|
housingneeds_f: "Yes", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
@ -898,7 +868,7 @@ RSpec.describe Form, type: :model do |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
}.to raise_error(ActiveRecord::RecordInvalid) |
|
|
|
|
|
|
|
|
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(housingneeds_a: "Yes", |
|
|
|
described_class.create!(housingneeds_a: "Yes", |
|
|
|
housingneeds_b: "Yes", |
|
|
|
housingneeds_b: "Yes", |
|
|
|
housingneeds_f: "Yes", |
|
|
|
housingneeds_f: "Yes", |
|
|
|
rent_type: "London Affordable rent", |
|
|
|
rent_type: "London Affordable rent", |
|
|
@ -908,10 +878,10 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "Validate reason for vacancy" do |
|
|
|
context "when validating reason for vacancy" do |
|
|
|
def check_rsnvac_validation(prevten) |
|
|
|
def check_rsnvac_validation(prevten) |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(rsnvac: "Relet to tenant who occupied same property as temporary accommodation", |
|
|
|
described_class.create!(rsnvac: "Relet to tenant who occupied same property as temporary accommodation", |
|
|
|
prevten: prevten, |
|
|
|
prevten: prevten, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -920,7 +890,7 @@ RSpec.describe Form, type: :model do |
|
|
|
|
|
|
|
|
|
|
|
def check_rsnvac_referral_validation(referral) |
|
|
|
def check_rsnvac_referral_validation(referral) |
|
|
|
expect { |
|
|
|
expect { |
|
|
|
CaseLog.create!(rsnvac: "Relet to tenant who occupied same property as temporary accommodation", |
|
|
|
described_class.create!(rsnvac: "Relet to tenant who occupied same property as temporary accommodation", |
|
|
|
referral: referral, |
|
|
|
referral: referral, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
owning_organisation: owning_organisation, |
|
|
|
managing_organisation: managing_organisation) |
|
|
|
managing_organisation: managing_organisation) |
|
|
@ -994,7 +964,7 @@ RSpec.describe Form, type: :model do |
|
|
|
require "date" |
|
|
|
require "date" |
|
|
|
let(:organisation) { FactoryBot.create(:organisation, "Org type": "PRP") } |
|
|
|
let(:organisation) { FactoryBot.create(:organisation, "Org type": "PRP") } |
|
|
|
let!(:case_log) do |
|
|
|
let!(:case_log) do |
|
|
|
CaseLog.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: organisation, |
|
|
|
managing_organisation: organisation, |
|
|
|
owning_organisation: organisation, |
|
|
|
owning_organisation: organisation, |
|
|
|
property_postcode: "M1 1AE", |
|
|
|
property_postcode: "M1 1AE", |
|
|
@ -1064,14 +1034,14 @@ RSpec.describe Form, type: :model do |
|
|
|
expect(record_from_db["year"]).to eq(2021) |
|
|
|
expect(record_from_db["year"]).to eq(2021) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "addresses" do |
|
|
|
context "when saving addresses" do |
|
|
|
before do |
|
|
|
before do |
|
|
|
stub_request(:get, /api.postcodes.io/) |
|
|
|
stub_request(:get, /api.postcodes.io/) |
|
|
|
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\"}}", headers: {}) |
|
|
|
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\"}}", headers: {}) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
let!(:address_case_log) do |
|
|
|
let!(:address_case_log) do |
|
|
|
CaseLog.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: organisation, |
|
|
|
managing_organisation: organisation, |
|
|
|
owning_organisation: organisation, |
|
|
|
owning_organisation: organisation, |
|
|
|
postcode_known: "Yes", |
|
|
|
postcode_known: "Yes", |
|
|
@ -1122,7 +1092,7 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "net_income" do |
|
|
|
context "when saving net_income" do |
|
|
|
it "infers the income frequency" do |
|
|
|
it "infers the income frequency" do |
|
|
|
case_log.update!(net_income_known: "Weekly") |
|
|
|
case_log.update!(net_income_known: "Weekly") |
|
|
|
expect(case_log.reload.incfreq).to eq("Weekly") |
|
|
|
expect(case_log.reload.incfreq).to eq("Weekly") |
|
|
@ -1133,9 +1103,9 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "rent and charges" do |
|
|
|
context "when saving rent and charges" do |
|
|
|
let!(:case_log) do |
|
|
|
let!(:case_log) do |
|
|
|
CaseLog.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: organisation, |
|
|
|
managing_organisation: organisation, |
|
|
|
owning_organisation: organisation, |
|
|
|
owning_organisation: organisation, |
|
|
|
brent: 5.77, |
|
|
|
brent: 5.77, |
|
|
@ -1151,9 +1121,9 @@ RSpec.describe Form, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "household members derived vars" do |
|
|
|
context "when validating household members derived vars" do |
|
|
|
let!(:household_case_log) do |
|
|
|
let!(:household_case_log) do |
|
|
|
CaseLog.create({ |
|
|
|
described_class.create({ |
|
|
|
managing_organisation: organisation, |
|
|
|
managing_organisation: organisation, |
|
|
|
owning_organisation: organisation, |
|
|
|
owning_organisation: organisation, |
|
|
|
other_hhmemb: 4, |
|
|
|
other_hhmemb: 4, |
|
|
@ -1201,12 +1171,13 @@ RSpec.describe Form, type: :model do |
|
|
|
let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: "Yes", preg_occ: "No") } |
|
|
|
let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: "Yes", preg_occ: "No") } |
|
|
|
|
|
|
|
|
|
|
|
it "clears the answer" do |
|
|
|
it "clears the answer" do |
|
|
|
expect { case_log.update!(preg_occ: nil) }.to change { case_log.cbl }.from("Yes").to(nil) |
|
|
|
expect { case_log.update!(preg_occ: nil) }.to change(case_log, :cbl).from("Yes").to(nil) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "two pages with the same question key, only one's dependency is met" do |
|
|
|
context "with two pages having the same question key, only one's dependency is met" do |
|
|
|
let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: "Yes", preg_occ: "No") } |
|
|
|
let(:case_log) { FactoryBot.create(:case_log, :in_progress, cbl: "Yes", preg_occ: "No") } |
|
|
|
|
|
|
|
|
|
|
|
it "does not clear the answer" do |
|
|
|
it "does not clear the answer" do |
|
|
|
expect(case_log.cbl).to eq("Yes") |
|
|
|
expect(case_log.cbl).to eq("Yes") |
|
|
|
end |
|
|
|
end |
|
|
|