Browse Source

feat: all staircasing transactions must have stairbought >= 1%

pull/1404/head
Sam Seed 3 years ago
parent
commit
f49c4f4f4a
  1. 2
      app/models/validations/sales/financial_validations.rb
  2. 23
      spec/models/validations/sales/financial_validations_spec.rb

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

@ -57,7 +57,7 @@ module Validations::Sales::FinancialValidations
if [2, 16, 18, 24].include? record.type if [2, 16, 18, 24].include? record.type
threshold = 10 threshold = 10
elsif record.type == 30 else
threshold = 1 threshold = 1
end end

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

@ -188,10 +188,25 @@ RSpec.describe Validations::Sales::FinancialValidations do
record.stairbought = 0 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 record.type = 30
financial_validator.validate_percentage_bought_at_least_threshold(record) financial_validator.validate_percentage_bought_at_least_threshold(record)
expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 1%"]) expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 1%"])
record.errors.clear 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 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 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.stairbought = 1
record.type = 30 record.type = 28
financial_validator.validate_percentage_bought_at_least_threshold(record) financial_validator.validate_percentage_bought_at_least_threshold(record)
expect(record.errors["stairbought"]).to be_empty expect(record.errors["stairbought"]).to be_empty
record.errors.clear 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) financial_validator.validate_percentage_bought_at_least_threshold(record)
expect(record.errors["stairbought"]).to be_empty expect(record.errors["stairbought"]).to be_empty
record.errors.clear record.errors.clear

Loading…
Cancel
Save