From 58f5658ed0ace63f5ede4993f9e2d56e24a029c0 Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Wed, 1 Feb 2023 16:43:23 +0000 Subject: [PATCH] correct linting errors and play a little code golf --- .../validations/sales/soft_validations.rb | 2 +- .../sales/financial_validations_spec.rb | 20 ++++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index a7fc4f4c0..61ac8bc3c 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -21,7 +21,7 @@ module Validations::Sales::SoftValidations def staircase_bought_above_fifty? stairbought && stairbought > 50 - end + end def mortgage_over_soft_max? return false unless mortgage && inc1mort && (inc2mort || not_joint_purchase?) diff --git a/spec/models/validations/sales/financial_validations_spec.rb b/spec/models/validations/sales/financial_validations_spec.rb index 22efbd8f9..d8ddd2dbd 100644 --- a/spec/models/validations/sales/financial_validations_spec.rb +++ b/spec/models/validations/sales/financial_validations_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Validations::Sales::FinancialValidations do describe "income validations for shared ownership" do let(:record) { FactoryBot.create(:sales_log, ownershipsch: 1) } - context "in a non london borough" do + context "when buying in a non london borough" do before do record.update!(la: "E08000035") record.reload @@ -78,7 +78,7 @@ RSpec.describe Validations::Sales::FinancialValidations do end end - context "in a london borough" do + context "when buying in a london borough" do before do record.update!(la: "E09000030") record.reload @@ -167,7 +167,7 @@ RSpec.describe Validations::Sales::FinancialValidations do it "does not add an error if the cash discount is in the expected range" do record.cashdis = 10_000 financial_validator.validate_cash_discount(record) - expect(record.errors["cashdis"]).to be_empty + expect(record.errors).to be_empty end end @@ -178,16 +178,14 @@ RSpec.describe Validations::Sales::FinancialValidations do record.stairbought = 20 record.stairowned = 40 financial_validator.validate_percentage_bought_not_greater_than_percentage_owned(record) - expect(record.errors["stairbought"]).to be_empty - expect(record.errors["stairowned"]).to be_empty + expect(record.errors).to be_empty end it "does not add an error if the percentage bought is equal to the percentage owned" do record.stairbought = 30 record.stairowned = 30 financial_validator.validate_percentage_bought_not_greater_than_percentage_owned(record) - expect(record.errors["stairbought"]).to be_empty - expect(record.errors["stairowned"]).to be_empty + expect(record.errors).to be_empty end it "adds an error to stairowned and not stairbought if the percentage bought is more than the percentage owned" do @@ -206,8 +204,7 @@ RSpec.describe Validations::Sales::FinancialValidations do record.type = 2 record.stairowned = 80 financial_validator.validate_percentage_owned_not_too_much_if_older_person(record) - expect(record.errors["stairowned"]).to be_empty - expect(record.errors["type"]).to be_empty + expect(record.errors).to be_empty end end @@ -216,8 +213,7 @@ RSpec.describe Validations::Sales::FinancialValidations do record.type = 24 record.stairowned = 50 financial_validator.validate_percentage_owned_not_too_much_if_older_person(record) - expect(record.errors["stairowned"]).to be_empty - expect(record.errors["type"]).to be_empty + expect(record.errors).to be_empty end it "adds an error when percentage owned after staircasing transaction exceeds 75%" do @@ -232,7 +228,7 @@ RSpec.describe Validations::Sales::FinancialValidations do describe "#validate_child_income" do let(:record) { FactoryBot.create(:sales_log) } - + context "when buyer 2 is not a child" do before do record.update!(ecstat2: rand(0..8))