From f49c4f4f4a1b5988e201962174cef8126280ab66 Mon Sep 17 00:00:00 2001 From: Sam Seed Date: Mon, 13 Mar 2023 11:20:28 +0000 Subject: [PATCH] feat: all staircasing transactions must have stairbought >= 1% --- .../sales/financial_validations.rb | 2 +- .../sales/financial_validations_spec.rb | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/models/validations/sales/financial_validations.rb b/app/models/validations/sales/financial_validations.rb index fd4d9ad26..7a5ab648a 100644 --- a/app/models/validations/sales/financial_validations.rb +++ b/app/models/validations/sales/financial_validations.rb @@ -57,7 +57,7 @@ module Validations::Sales::FinancialValidations if [2, 16, 18, 24].include? record.type threshold = 10 - elsif record.type == 30 + else threshold = 1 end diff --git a/spec/models/validations/sales/financial_validations_spec.rb b/spec/models/validations/sales/financial_validations_spec.rb index 142143976..d3446bdee 100644 --- a/spec/models/validations/sales/financial_validations_spec.rb +++ b/spec/models/validations/sales/financial_validations_spec.rb @@ -188,10 +188,25 @@ RSpec.describe Validations::Sales::FinancialValidations do record.stairbought = 0 + record.type = 28 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 1%"]) + record.errors.clear + record.type = 30 financial_validator.validate_percentage_bought_at_least_threshold(record) expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 1%"]) record.errors.clear + + record.type = 31 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 1%"]) + record.errors.clear + + record.type = 32 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 1%"]) + record.errors.clear end it "doesn't add an error to stairbought if the percentage bought is greater than or equal to the threshold (which depends on the shared ownership type)" do @@ -219,16 +234,12 @@ RSpec.describe Validations::Sales::FinancialValidations do record.stairbought = 1 - record.type = 30 + record.type = 28 financial_validator.validate_percentage_bought_at_least_threshold(record) expect(record.errors["stairbought"]).to be_empty record.errors.clear - end - - it "doesn't add an error to stairbought if the percentage bought is less than the smallest possible threshold and the shared ownership type is not one which should have a threshold associated with it" do - record.stairbought = 0 - record.type = 28 + record.type = 30 financial_validator.validate_percentage_bought_at_least_threshold(record) expect(record.errors["stairbought"]).to be_empty record.errors.clear