Browse Source

Merge branch 'main' into PhoneExtension

pull/2597/head
Rachael Booth 2 years ago committed by GitHub
parent
commit
6ad373a4f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      Gemfile.lock
  2. 4
      app/models/sales_log.rb
  3. 3
      app/models/validations/sales/financial_validations.rb
  4. 10
      spec/models/validations/sales/financial_validations_spec.rb

8
Gemfile.lock

@ -141,7 +141,7 @@ GEM
coderay (1.1.3)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
concurrent-ruby (1.3.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crack (1.0.0)
bigdecimal
@ -180,7 +180,7 @@ GEM
rubocop
smart_properties
erubi (1.13.0)
et-orbi (1.2.7)
et-orbi (1.2.11)
tzinfo
event_stream_parser (1.0.0)
excon (0.109.0)
@ -198,8 +198,8 @@ GEM
faraday-net_http (3.1.0)
net-http
ffi (1.16.3)
fugit (1.10.0)
et-orbi (~> 1, >= 1.2.7)
fugit (1.11.1)
et-orbi (~> 1, >= 1.2.11)
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)

4
app/models/sales_log.rb

@ -542,4 +542,8 @@ class SalesLog < Log
def address_search_given?
address_line1_input.present? && postcode_full_input.present?
end
def is_resale?
resale == 1
end
end

3
app/models/validations/sales/financial_validations.rb

@ -96,9 +96,10 @@ module Validations::Sales::FinancialValidations
if record.equity < range.min
record.errors.add :type, I18n.t("validations.financial.equity.under_min", min_equity: range.min)
record.errors.add :equity, :under_min, message: I18n.t("validations.financial.equity.under_min", min_equity: range.min)
elsif record.equity > range.max
elsif !record.is_resale? && record.equity > range.max
record.errors.add :type, I18n.t("validations.financial.equity.over_max", max_equity: range.max)
record.errors.add :equity, :over_max, message: I18n.t("validations.financial.equity.over_max", max_equity: range.max)
record.errors.add :resale, I18n.t("validations.financial.equity.over_max", max_equity: range.max)
end
end

10
spec/models/validations/sales/financial_validations_spec.rb

@ -338,7 +338,7 @@ RSpec.describe Validations::Sales::FinancialValidations do
end
describe "#validate_equity_in_range_for_year_and_type" do
let(:record) { FactoryBot.build(:sales_log, saledate:) }
let(:record) { FactoryBot.build(:sales_log, saledate:, resale: nil) }
context "with a log in the 22/23 collection year" do
let(:saledate) { Time.zone.local(2023, 1, 1) }
@ -373,6 +373,14 @@ RSpec.describe Validations::Sales::FinancialValidations do
expect(record.errors["equity"]).to include(match I18n.t("validations.financial.equity.over_max", max_equity: 75))
expect(record.errors["type"]).to include(match I18n.t("validations.financial.equity.over_max", max_equity: 75))
end
it "does not add an error if it's a resale" do
record.type = 2
record.equity = 90
record.resale = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors).to be_empty
end
end
context "with a log in 23/24 collection year" do

Loading…
Cancel
Save