Browse Source

Unit tests

pull/297/head
baarkerlounger 3 years ago
parent
commit
ba060e5f70
  1. 69
      spec/models/case_log_spec.rb

69
spec/models/case_log_spec.rb

@ -18,26 +18,6 @@ RSpec.describe CaseLog do
end
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
expect {
described_class.create!(
@ -89,15 +69,6 @@ RSpec.describe CaseLog do
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "validates bedroom number" do
expect {
described_class.create!(unittype_gn: "Shared house",
beds: 0,
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to raise_error(ActiveRecord::RecordInvalid)
end
context "when a reasonable preference is set to yes" do
it "validates that previously homeless should be selected" do
expect {
@ -357,17 +328,6 @@ RSpec.describe CaseLog do
end
end
context "when validating fixed term tenancy" do
it "Must not be completed if Type of main tenancy is not responded with either Secure or Assured shorthold " do
expect {
described_class.create!(tenancy: "Other",
tenancylength: 10,
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "when validating armed forces is active" do
it "must not be answered if not ever served as a regular" do
expect {
@ -800,6 +760,35 @@ RSpec.describe CaseLog do
end
end
describe "#update" do
let(:case_log) { FactoryBot.create(:case_log) }
let(:validator) { case_log._validators[nil].first }
after do
case_log.update(age1: 25)
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
it "validates tenancy length for tenancy type" do
expect(validator).to receive(:validate_fixed_term_tenancy)
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
end
describe "status" do
let!(:empty_case_log) { FactoryBot.create(:case_log) }
let!(:in_progress_case_log) { FactoryBot.create(:case_log, :in_progress) }

Loading…
Cancel
Save