Browse Source

Format errors on money amounts with 2 decimals

pull/1493/head
Jack S 3 years ago
parent
commit
1cf5b92d7a
  1. 4
      app/models/lettings_log.rb
  2. 2
      app/models/sales_log.rb
  3. 4
      spec/models/lettings_log_spec.rb
  4. 2
      spec/models/sales_log_spec.rb
  5. 32
      spec/models/validations/financial_validations_spec.rb
  6. 2
      spec/services/imports/lettings_logs_import_service_spec.rb

4
app/models/lettings_log.rb

@ -149,7 +149,7 @@ class LettingsLog < Log
def weekly_to_value_per_period(field_value) def weekly_to_value_per_period(field_value)
num_of_weeks = NUM_OF_WEEKS_FROM_PERIOD[period] num_of_weeks = NUM_OF_WEEKS_FROM_PERIOD[period]
((field_value * 52) / num_of_weeks).round(2) sprintf("%.2f", (field_value * 52) / num_of_weeks)
end end
def applicable_income_range def applicable_income_range
@ -650,7 +650,7 @@ private
num_of_weeks = NUM_OF_WEEKS_FROM_PERIOD[period] num_of_weeks = NUM_OF_WEEKS_FROM_PERIOD[period]
return "" unless value && num_of_weeks return "" unless value && num_of_weeks
(value * 52 / num_of_weeks).round(2) sprintf("%.2f", (value * 52 / num_of_weeks))
end end
def fully_wheelchair_accessible? def fully_wheelchair_accessible?

2
app/models/sales_log.rb

@ -223,7 +223,7 @@ class SalesLog < Log
def expected_shared_ownership_deposit_value def expected_shared_ownership_deposit_value
return unless value && equity return unless value && equity
(value * equity / 100).round(2) sprintf("%.2f", (value * equity / 100))
end end
def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key) def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key)

4
spec/models/lettings_log_spec.rb

@ -2605,12 +2605,12 @@ RSpec.describe LettingsLog do
context "when period is weekly for 52 weeks" do context "when period is weekly for 52 weeks" do
it "returns weekly soft min for 52 weeks" do it "returns weekly soft min for 52 weeks" do
lettings_log.period = 1 lettings_log.period = 1
expect(lettings_log.soft_min_for_period).to eq("100.0 every week") expect(lettings_log.soft_min_for_period).to eq("100.00 every week")
end end
it "returns weekly soft max for 52 weeks" do it "returns weekly soft max for 52 weeks" do
lettings_log.period = 1 lettings_log.period = 1
expect(lettings_log.soft_max_for_period).to eq("400.0 every week") expect(lettings_log.soft_max_for_period).to eq("400.00 every week")
end end
end end

2
spec/models/sales_log_spec.rb

@ -498,7 +498,7 @@ RSpec.describe SalesLog, type: :model do
let!(:completed_sales_log) { create(:sales_log, :completed, ownershipsch: 1, type: 2, value: 1000, equity: 50) } let!(:completed_sales_log) { create(:sales_log, :completed, ownershipsch: 1, type: 2, value: 1000, equity: 50) }
it "is set to completed for a completed sales log" do it "is set to completed for a completed sales log" do
expect(completed_sales_log.expected_shared_ownership_deposit_value).to eq(500) expect(completed_sales_log.expected_shared_ownership_deposit_value).to eq("500.00")
end end
end end

32
spec/models/validations/financial_validations_spec.rb

@ -919,9 +919,9 @@ RSpec.describe Validations::FinancialValidations do
record.chcharge = 1001 record.chcharge = 1001
financial_validator.validate_care_home_charges(record) financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"]) expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 10, period: "weekly for 52 weeks", max_chcharge: 1000)) .to include("Household rent and other charges must be between 10.00 and 1000.00 if paying weekly for 52 weeks")
expect(record.errors["period"]) expect(record.errors["period"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 10, period: "weekly for 52 weeks", max_chcharge: 1000)) .to include("Household rent and other charges must be between 10.00 and 1000.00 if paying weekly for 52 weeks")
end end
it "validates charge when period is monthly" do it "validates charge when period is monthly" do
@ -929,9 +929,9 @@ RSpec.describe Validations::FinancialValidations do
record.chcharge = 4334 record.chcharge = 4334
financial_validator.validate_care_home_charges(record) financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"]) expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 43, period: "every calendar month", max_chcharge: 4333)) .to include("Household rent and other charges must be between 43.00 and 4333.00 if paying every calendar month")
expect(record.errors["period"]) expect(record.errors["period"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 43, period: "every calendar month", max_chcharge: 4333)) .to include("Household rent and other charges must be between 43.00 and 4333.00 if paying every calendar month")
end end
it "validates charge when period is every 2 weeks" do it "validates charge when period is every 2 weeks" do
@ -939,9 +939,9 @@ RSpec.describe Validations::FinancialValidations do
record.chcharge = 2001 record.chcharge = 2001
financial_validator.validate_care_home_charges(record) financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"]) expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 20, period: "every 2 weeks", max_chcharge: 2000)) .to include("Household rent and other charges must be between 20.00 and 2000.00 if paying every 2 weeks")
expect(record.errors["period"]) expect(record.errors["period"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 20, period: "every 2 weeks", max_chcharge: 2000)) .to include("Household rent and other charges must be between 20.00 and 2000.00 if paying every 2 weeks")
end end
it "validates charge when period is every 4 weeks" do it "validates charge when period is every 4 weeks" do
@ -949,9 +949,9 @@ RSpec.describe Validations::FinancialValidations do
record.chcharge = 4001 record.chcharge = 4001
financial_validator.validate_care_home_charges(record) financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"]) expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 40, period: "every 4 weeks", max_chcharge: 4000)) .to include("Household rent and other charges must be between 40.00 and 4000.00 if paying every 4 weeks")
expect(record.errors["period"]) expect(record.errors["period"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 40, period: "every 4 weeks", max_chcharge: 4000)) .to include("Household rent and other charges must be between 40.00 and 4000.00 if paying every 4 weeks")
end end
end end
@ -1007,9 +1007,9 @@ RSpec.describe Validations::FinancialValidations do
record.chcharge = 9 record.chcharge = 9
financial_validator.validate_care_home_charges(record) financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"]) expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 10, period: "weekly for 52 weeks", max_chcharge: 1000)) .to include("Household rent and other charges must be between 10.00 and 1000.00 if paying weekly for 52 weeks")
expect(record.errors["period"]) expect(record.errors["period"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 10, period: "weekly for 52 weeks", max_chcharge: 1000)) .to include("Household rent and other charges must be between 10.00 and 1000.00 if paying weekly for 52 weeks")
end end
it "validates charge when period is monthly" do it "validates charge when period is monthly" do
@ -1017,9 +1017,9 @@ RSpec.describe Validations::FinancialValidations do
record.chcharge = 42 record.chcharge = 42
financial_validator.validate_care_home_charges(record) financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"]) expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 43, period: "every calendar month", max_chcharge: 4333)) .to include("Household rent and other charges must be between 43.00 and 4333.00 if paying every calendar month")
expect(record.errors["period"]) expect(record.errors["period"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 43, period: "every calendar month", max_chcharge: 4333)) .to include("Household rent and other charges must be between 43.00 and 4333.00 if paying every calendar month")
end end
it "validates charge when period is every 2 weeks" do it "validates charge when period is every 2 weeks" do
@ -1027,9 +1027,9 @@ RSpec.describe Validations::FinancialValidations do
record.chcharge = 19 record.chcharge = 19
financial_validator.validate_care_home_charges(record) financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"]) expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 20, period: "every 2 weeks", max_chcharge: 2000)) .to include("Household rent and other charges must be between 20.00 and 2000.00 if paying every 2 weeks")
expect(record.errors["period"]) expect(record.errors["period"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 20, period: "every 2 weeks", max_chcharge: 2000)) .to include("Household rent and other charges must be between 20.00 and 2000.00 if paying every 2 weeks")
end end
it "validates charge when period is every 4 weeks" do it "validates charge when period is every 4 weeks" do
@ -1037,9 +1037,9 @@ RSpec.describe Validations::FinancialValidations do
record.chcharge = 39 record.chcharge = 39
financial_validator.validate_care_home_charges(record) financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"]) expect(record.errors["chcharge"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 40, period: "every 4 weeks", max_chcharge: 4000)) .to include("Household rent and other charges must be between 40.00 and 4000.00 if paying every 4 weeks")
expect(record.errors["period"]) expect(record.errors["period"])
.to include(match I18n.t("validations.financial.carehome.out_of_range", min_chcharge: 40, period: "every 4 weeks", max_chcharge: 4000)) .to include("Household rent and other charges must be between 40.00 and 4000.00 if paying every 4 weeks")
end end
end end
end end

2
spec/services/imports/lettings_logs_import_service_spec.rb

@ -762,7 +762,7 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
it "intercepts the relevant validation error" do it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing chcharge with error: Household rent and other charges must be between £10 and £1000 if paying weekly for 52 weeks/) expect(logger).to receive(:warn).with(/Removing chcharge with error: Household rent and other charges must be between £10.00 and £1000.00 if paying weekly for 52 weeks/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) } expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error .not_to raise_error
end end

Loading…
Cancel
Save