Browse Source

CLDC-1880 Add mortgage length validations

CLDC-1880-mortgage-length-validations
Jack S 2 years ago
parent
commit
898eb0bcc4
  1. 8
      app/models/validations/sales/sale_information_validations.rb
  2. 2
      config/locales/en.yml
  3. 36
      spec/models/validations/sales/sale_information_validations_spec.rb

8
app/models/validations/sales/sale_information_validations.rb

@ -54,4 +54,12 @@ module Validations::Sales::SaleInformationValidations
end end
end end
end end
def validate_mortgage_length(record)
return unless record.mortlen
return if record.mortlen >= 0 && record.mortlen <= 60
record.errors.add :mortlen, I18n.t("validations.sale_information.mortlen.range")
end
end end

2
config/locales/en.yml

@ -426,6 +426,8 @@ en:
previous_property_type: previous_property_type:
property_type_bedsit: "A bedsit can not have more than 1 bedroom" property_type_bedsit: "A bedsit can not have more than 1 bedroom"
discounted_ownership_value: "Mortgage, deposit, and grant total must equal £%{value_with_discount}" discounted_ownership_value: "Mortgage, deposit, and grant total must equal £%{value_with_discount}"
mortlen:
range: Mortgage length must be between 0 and 60
soft_validations: soft_validations:
net_income: net_income:

36
spec/models/validations/sales/sale_information_validations_spec.rb

@ -145,7 +145,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
describe "#validate_previous_property_unit_type" do describe "#validate_previous_property_unit_type" do
context "when number of bedrooms is <= 1" do context "when number of bedrooms is <= 1" do
let(:record) { FactoryBot.build(:sales_log, frombeds: 1, fromprop: 2) } let(:record) { build(:sales_log, frombeds: 1, fromprop: 2) }
it "does not add an error if it's a bedsit" do it "does not add an error if it's a bedsit" do
sale_information_validator.validate_previous_property_unit_type(record) sale_information_validator.validate_previous_property_unit_type(record)
@ -155,7 +155,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
context "when number of bedrooms is > 1" do context "when number of bedrooms is > 1" do
let(:record) { FactoryBot.build(:sales_log, frombeds: 2, fromprop: 2) } let(:record) { build(:sales_log, frombeds: 2, fromprop: 2) }
it "does add an error if it's a bedsit" do it "does add an error if it's a bedsit" do
sale_information_validator.validate_previous_property_unit_type(record) sale_information_validator.validate_previous_property_unit_type(record)
@ -371,4 +371,36 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
end end
end end
describe "#validate_mortgage_length" do
context "when mortlen is < 0" do
let(:record) { build(:sales_log, mortlen: -1) }
it "does not add an error if it's a bedsit" do
sale_information_validator.validate_mortgage_length(record)
expect(record.errors[:mortlen]).to include(I18n.t("validations.sale_information.mortlen.range"))
end
end
context "when 0<= mortlen <= 60" do
let(:record) { build(:sales_log, mortlen: 20) }
it "does not add an error if it's a bedsit" do
sale_information_validator.validate_mortgage_length(record)
expect(record.errors).to be_empty
end
end
context "when mortlen > 60" do
let(:record) { build(:sales_log, mortlen: 61) }
it "does not add an error if it's a bedsit" do
sale_information_validator.validate_mortgage_length(record)
expect(record.errors[:mortlen]).to include(I18n.t("validations.sale_information.mortlen.range"))
end
end
end
end end

Loading…
Cancel
Save