Browse Source

Enforce offered as integer (#1897)

* feat: ensure offered is an integer (decimal 0 was triggering validation errors)

* feat: allow decimals but clear when not integer equivalent as per new requirements
pull/1900/head v0.3.54
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
e5e6e1e21a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/validations/shared_validations.rb
  2. 1
      app/services/imports/lettings_logs_import_service.rb
  3. 21
      spec/services/imports/lettings_logs_import_service_spec.rb

2
app/models/validations/shared_validations.rb

@ -49,7 +49,7 @@ module Validations::SharedValidations
elsif incorrect_accuracy || value.to_d != value.to_i # if the user enters a value in exponent notation (eg '4e1') the to_i method does not convert this to the correct value
field = question.check_answer_label || question.id
case question.step
when 1 then record.errors.add question.id.to_sym, I18n.t("validations.numeric.whole_number", field:)
when 1 then record.errors.add question.id.to_sym, :not_integer, message: I18n.t("validations.numeric.whole_number", field:)
when 10 then record.errors.add question.id.to_sym, I18n.t("validations.numeric.nearest_ten", field:)
end
end

1
app/services/imports/lettings_logs_import_service.rb

@ -326,6 +326,7 @@ module Imports
%i[prevten non_temp_accommodation] => %w[prevten rsnvac],
%i[joint not_joint_tenancy] => %w[joint],
%i[offered outside_the_range] => %w[offered],
%i[offered not_integer] => %w[offered],
%i[earnings over_hard_max] => %w[ecstat1],
%i[tshortfall no_outstanding_charges] => %w[tshortfall hbrentshortfall],
%i[beds outside_the_range] => %w[beds],

21
spec/services/imports/lettings_logs_import_service_spec.rb

@ -545,6 +545,27 @@ RSpec.describe Imports::LettingsLogsImportService do
end
end
context "and the number of times the property was relet is 0.01" do
before do
lettings_log_xml.at_xpath("//xmlns:Q20").content = "0.01"
end
it "intercepts the relevant validation error" do
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
it "clears out the number offered answer" do
allow(logger).to receive(:warn)
lettings_log_service.send(:create_log, lettings_log_xml)
lettings_log = LettingsLog.find_by(old_id: lettings_log_id)
expect(lettings_log).not_to be_nil
expect(lettings_log.offered).to be_nil
end
end
context "and the gender identity is refused" do
before do
lettings_log_xml.at_xpath("//xmlns:P1Sex").content = "Person prefers not to say"

Loading…
Cancel
Save