Browse Source

Add shared_ownership_deposit_invalid? soft validation

cldc-875-sales-validations-shared-ownership-cash-deposit-amount
Kat 2 years ago committed by Sam Seed
parent
commit
af79571913
  1. 6
      app/models/validations/sales/soft_validations.rb
  2. 79
      spec/models/validations/sales/soft_validations_spec.rb

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

@ -37,6 +37,12 @@ module Validations::Sales::SoftValidations
deposit > savings * 4 / 3
end
def shared_ownership_deposit_invalid?
return unless mortgage && deposit && cashdis && value && equity
mortgage + deposit + cashdis != value * equity / 100
end
def hodate_3_years_or_more_saledate?
return unless hodate && saledate

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

@ -254,6 +254,85 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_deposit_over_soft_max
end
end
context "when validating shared ownership deposit" do
it "returns false if MORTGAGE + DEPOSIT + CASHDIS are equal VALUE * EQUITY/100" do
record.mortgage = 1000
record.deposit = 1000
record.cashdis = 1000
record.value = 3000
record.equity = 100
expect(record)
.not_to be_shared_ownership_deposit_invalid
end
it "returns false if no mortgage is given" do
record.mortgage = nil
record.deposit = 1000
record.cashdis = 1000
record.value = 3000
record.equity = 100
expect(record)
.not_to be_shared_ownership_deposit_invalid
end
it "returns false if no deposit is given" do
record.mortgage = 1000
record.deposit = nil
record.cashdis = 1000
record.value = 3000
record.equity = 100
expect(record)
.not_to be_shared_ownership_deposit_invalid
end
it "returns false if no cashdis is given" do
record.mortgage = 1000
record.deposit = 1000
record.cashdis = nil
record.value = 3000
record.equity = 100
expect(record)
.not_to be_shared_ownership_deposit_invalid
end
it "returns false if no value is given" do
record.mortgage = 1000
record.deposit = 1000
record.cashdis = 1000
record.value = nil
record.equity = 100
expect(record)
.not_to be_shared_ownership_deposit_invalid
end
it "returns false if no equity is given" do
record.mortgage = 1000
record.deposit = 1000
record.cashdis = 1000
record.value = 3000
record.equity = nil
expect(record)
.not_to be_shared_ownership_deposit_invalid
end
it "returns true if MORTGAGE + DEPOSIT + CASHDIS are not equal VALUE * EQUITY/100" do
record.mortgage = 1000
record.deposit = 1000
record.cashdis = 1000
record.value = 4323
record.equity = 100
expect(record)
.to be_shared_ownership_deposit_invalid
end
end
end
describe "hodate_more_than_3_years_before_saledate" do

Loading…
Cancel
Save