Browse Source

feat: allow decimals but clear when not integer equivalent as per new requirements

pull/1895/head
natdeanlewissoftwire 3 years ago
parent
commit
d27ac39a16
  1. 2
      app/models/validations/shared_validations.rb
  2. 3
      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

3
app/services/imports/lettings_logs_import_service.rb

@ -174,7 +174,7 @@ module Imports
0
end
attributes["offered"] = safe_string_as_integer(xml_doc, "Q20")
attributes["offered"] = safe_string_as_decimal(xml_doc, "Q20")
attributes["propcode"] = string_or_nil(xml_doc, "Q21a")
attributes["beds"] = safe_string_as_integer(xml_doc, "Q22")
attributes["unittype_gn"] = unsafe_string_as_integer(xml_doc, "Q23")
@ -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