Browse Source

Merge branch 'main' into CLDC-3245-make-q59-optional

pull/2268/head
Robert Sullivan 2 years ago committed by GitHub
parent
commit
48385501a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      app/models/log.rb
  2. 8
      app/models/validations/sales/soft_validations.rb
  3. 20
      spec/models/lettings_log_spec.rb
  4. 50
      spec/models/log_spec.rb
  5. 23
      spec/models/validations/sales/soft_validations_spec.rb

1
app/models/log.rb

@ -179,6 +179,7 @@ class Log < ApplicationRecord
def blank_compound_invalid_non_setup_fields!
self.ppcodenk = nil if errors.attribute_names.include? :ppostcode_full
self.previous_la_known = nil if errors.attribute_names.include? :prevloc
if errors.of_kind?(:uprn, :uprn_error)
self.uprn_known = nil

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

@ -89,9 +89,11 @@ module Validations::Sales::SoftValidations
return unless cashdis || !is_type_discount?
return unless deposit && value && equity
cash_discount = cashdis || 0
mortgage_value = mortgage || 0
mortgage_value + deposit + cash_discount != value * equity / 100
!within_tolerance?(mortgage_deposit_and_discount_total, value * equity / 100, 1)
end
def within_tolerance?(expected, actual, tolerance)
(expected - actual).abs <= tolerance
end
def mortgage_plus_deposit_less_than_discounted_value?

20
spec/models/lettings_log_spec.rb

@ -3382,26 +3382,6 @@ RSpec.describe LettingsLog do
end
end
describe "#blank_invalid_non_setup_fields!" do
context "when a setup field is invalid" do
subject(:model) { described_class.new(needstype: 404) }
it "does not blank it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.not_to change(model, :needstype)
end
end
context "when a non setup field is invalid" do
subject(:model) { build(:lettings_log, :completed, offered: 234) }
it "blanks it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.to change(model, :offered)
end
end
end
describe "#beds_for_la_rent_range" do
context "when beds nil" do
let(:lettings_log) { build(:lettings_log, beds: nil) }

50
spec/models/log_spec.rb

@ -27,4 +27,54 @@ RSpec.describe Log, type: :model do
expect(in_progress_lettings_log.calculate_status).to eq "in_progress"
end
end
describe "#blank_invalid_non_setup_fields!" do
context "when a setup field is invalid for a lettings log" do
subject(:model) { build(:lettings_log, needstype: 404) }
it "does not blank it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.not_to change(model, :needstype)
end
end
context "when a setup field is invalid for a sales log" do
subject(:model) { build(:sales_log, companybuy: 404) }
it "does not blank it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.not_to change(model, :companybuy)
end
end
context "when a non setup field is invalid for a lettings log" do
subject(:model) { build(:lettings_log, :completed, offered: 234) }
it "blanks it" do
model.valid?
model.blank_invalid_non_setup_fields!
expect(model.offered).to be_nil
end
end
context "when a non setup field is invalid for a sales log" do
subject(:model) { build(:sales_log, :completed, age1: 10) }
it "blanks it" do
model.valid?
model.blank_invalid_non_setup_fields!
expect(model.age1).to be_nil
end
end
context "when prevloc is invalid for a lettings log" do
subject(:model) { build(:lettings_log, :completed, previous_la_known: 1, prevloc: nil) }
it "blanks previous_la_known" do
model.valid?
model.blank_invalid_non_setup_fields!
expect(model.previous_la_known).to be_nil
end
end
end
end

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

@ -415,6 +415,17 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_shared_ownership_deposit_invalid
end
it "returns false if MORTGAGE + DEPOSIT + CASHDIS are within 1£ of VALUE * EQUITY/100" do
record.mortgage = 500
record.deposit = 500
record.cashdis = 500
record.value = 3001
record.equity = 50
expect(record)
.not_to be_shared_ownership_deposit_invalid
end
it "returns false if mortgage is used and no mortgage is given" do
record.mortgage = nil
record.deposit = 1000
@ -473,6 +484,18 @@ RSpec.describe Validations::Sales::SoftValidations do
.to be_shared_ownership_deposit_invalid
end
it "returns false if no cashdis not routed to and MORTGAGE + DEPOSIT are within 1£ of VALUE * EQUITY/100" do
record.mortgage = 500
record.deposit = 500
record.type = 2
record.cashdis = nil
record.value = 1999
record.equity = 50
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

Loading…
Cancel
Save