Browse Source

Migration fixes (#1881)

* feat: make offered unsafe as 0.00 is an expected value

* feat: add correct refused options for sex and relat questions

* refactor: lint

* feat: use safe_string_as_decimal
pull/1884/head
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
2256cc9d73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/services/imports/lettings_logs_import_service.rb
  2. 4
      app/services/imports/logs_import_service.rb
  3. 57
      spec/services/imports/lettings_logs_import_service_spec.rb

2
app/services/imports/lettings_logs_import_service.rb

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

4
app/services/imports/logs_import_service.rb

@ -106,7 +106,7 @@ module Imports
"F" "F"
when "Other", "Non-binary" when "Other", "Non-binary"
"X" "X"
when "Refused" when "Refused", "Person prefers not to say", "Buyer prefers not to say"
"R" "R"
end end
end end
@ -120,7 +120,7 @@ module Imports
"P" "P"
when "Other", "Non-binary" when "Other", "Non-binary"
"X" "X"
when "Refused", "Buyer prefers not to say" when "Refused", "Person prefers not to say", "Buyer prefers not to say"
"R" "R"
end end
end end

57
spec/services/imports/lettings_logs_import_service_spec.rb

@ -442,6 +442,63 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
end end
context "and the number of times the property was relet is 0.00" do
before do
lettings_log_xml.at_xpath("//xmlns:Q20").content = "0.00"
end
it "does not raise an error" do
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
it "does not clear offered answer" do
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 equal(0)
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"
end
it "does not raise an error" do
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
it "saves the correct answer" do
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.sex1).to eq("R")
end
end
context "and the relationship is refused" do
before do
lettings_log_xml.at_xpath("//xmlns:P2Rel").content = "Person prefers not to say"
end
it "does not raise an error" do
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
it "saves the correct answer" do
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.relat2).to eq("R")
end
end
context "when the log being imported was manually entered" do context "when the log being imported was manually entered" do
it "sets the creation method correctly" do it "sets the creation method correctly" do
lettings_log_service.send(:create_log, lettings_log_xml) lettings_log_service.send(:create_log, lettings_log_xml)

Loading…
Cancel
Save