Browse Source

CLDC-4175: remove redundant range validation

pull/3200/head
Nat Dean-Lewis 2 months ago
parent
commit
0351e06e6f
  1. 10
      app/models/validations/sales/financial_validations.rb
  2. 2
      config/locales/validations/sales/financial.en.yml
  3. 40
      spec/models/validations/sales/financial_validations_spec.rb

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

@ -139,16 +139,6 @@ module Validations::Sales::FinancialValidations
end
end
def validate_newservicecharges(record)
return unless record.newservicecharges
if record.newservicecharges.negative?
record.errors.add :newservicecharges, I18n.t("validations.sales.financial.newservicecharges.negative")
elsif record.newservicecharges > 9999.99
record.errors.add :newservicecharges, I18n.t("validations.sales.financial.newservicecharges.over_max")
end
end
def validate_newservicecharges_different_from_mscharge(record)
return unless record.hasservicechargeschanged == 1 && record.newservicecharges && record.mscharge

2
config/locales/validations/sales/financial.en.yml

@ -51,8 +51,6 @@ en:
same_as_new: "You said that the service charge will change and you entered the same amount as the new service charge. If the service charge will not change, answer 'No' to that question before entering the service charge here."
newservicecharges:
negative: "Service charge cannot be negative."
over_max: "Service charge cannot be higher than £9,999.99."
same_as_previous: "You said that the service charge will change and you entered the same amount as the previous question. If the service charge will not change, answer 'No'."
resale:

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

@ -479,46 +479,6 @@ RSpec.describe Validations::Sales::FinancialValidations do
end
end
describe "#validate_newservicecharges" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 1, staircase: 1) }
it "does not add errors when newservicecharges is nil" do
record.newservicecharges = nil
financial_validator.validate_newservicecharges(record)
expect(record.errors).to be_empty
end
it "does not add errors when newservicecharges is valid" do
record.newservicecharges = 100.50
financial_validator.validate_newservicecharges(record)
expect(record.errors).to be_empty
end
it "adds an error when newservicecharges is negative" do
record.newservicecharges = -50
financial_validator.validate_newservicecharges(record)
expect(record.errors["newservicecharges"]).to include(match I18n.t("validations.sales.financial.newservicecharges.negative"))
end
it "adds an error when newservicecharges is over the maximum" do
record.newservicecharges = 10_000
financial_validator.validate_newservicecharges(record)
expect(record.errors["newservicecharges"]).to include(match I18n.t("validations.sales.financial.newservicecharges.over_max"))
end
it "does not add errors when newservicecharges is exactly the maximum" do
record.newservicecharges = 9999.99
financial_validator.validate_newservicecharges(record)
expect(record.errors).to be_empty
end
it "does not add errors when newservicecharges is zero" do
record.newservicecharges = 0
financial_validator.validate_newservicecharges(record)
expect(record.errors).to be_empty
end
end
describe "#validate_newservicecharges_different_from_mscharge" do
let(:record) { FactoryBot.build(:sales_log, ownershipsch: 1, staircase: 1) }

Loading…
Cancel
Save