Browse Source

Add monthly_charges_over_soft_max soft validation

pull/1247/head
Kat 3 years ago
parent
commit
9a38622f44
  1. 7
      app/models/validations/sales/soft_validations.rb
  2. 62
      spec/models/validations/sales/soft_validations_spec.rb

7
app/models/validations/sales/soft_validations.rb

@ -75,4 +75,11 @@ module Validations::Sales::SoftValidations
!grant.between?(9_000, 16_000)
end
def monthly_charges_over_soft_max?
return unless type && mscharge && proptype
soft_max = old_persons_shared_ownership? ? 550 : 300
mscharge > soft_max
end
end

62
spec/models/validations/sales/soft_validations_spec.rb

@ -593,4 +593,66 @@ RSpec.describe Validations::Sales::SoftValidations do
expect(record).to be_staircase_bought_above_fifty
end
end
describe "#monthly_charges_over_soft_max?" do
it "returns false if mscharge is not given" do
record.mscharge = nil
record.proptype = 4
record.type = 2
expect(record).not_to be_monthly_charges_over_soft_max
end
it "returns false if proptype is not given" do
record.mscharge = 999
record.proptype = nil
record.type = 2
expect(record).not_to be_monthly_charges_over_soft_max
end
it "returns false if type is not given" do
record.mscharge = 999
record.proptype = 4
record.type = nil
expect(record).not_to be_monthly_charges_over_soft_max
end
context "with old persons shared ownership" do
it "returns false if the monthly charge is under 550" do
record.mscharge = 540
record.proptype = 4
record.type = 24
expect(record).not_to be_monthly_charges_over_soft_max
end
it "returns true if the monthly charge is over 550" do
record.mscharge = 999
record.proptype = 4
record.type = 24
expect(record).to be_monthly_charges_over_soft_max
end
end
context "with non old persons type of ownership" do
it "returns false if the monthly charge is under 300" do
record.mscharge = 280
record.proptype = 4
record.type = 18
expect(record).not_to be_monthly_charges_over_soft_max
end
it "returns true if the monthly charge is over 300" do
record.mscharge = 400
record.proptype = 4
record.type = 18
expect(record).to be_monthly_charges_over_soft_max
end
end
end
end

Loading…
Cancel
Save