Browse Source

feat: match locations/schemes with leading zeroes in bulk upload

pull/2024/head
natdeanlewissoftwire 1 year ago
parent
commit
c0f312cfe7
  1. 2
      app/models/location.rb
  2. 4
      app/models/scheme.rb
  3. 26
      spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb
  4. 27
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

2
app/models/location.rb

@ -110,7 +110,7 @@ class Location < ApplicationRecord
def self.find_by_id_on_multiple_fields(id) def self.find_by_id_on_multiple_fields(id)
return if id.nil? return if id.nil?
where(id:).or(where(old_visible_id: id)).first where(id:).or(where("ltrim(old_visible_id, '0') = ?", id.to_s)).first
end end
def postcode=(postcode) def postcode=(postcode)

4
app/models/scheme.rb

@ -169,9 +169,9 @@ class Scheme < ApplicationRecord
if scheme_id.start_with?("S") if scheme_id.start_with?("S")
where(id: scheme_id[1..]).first where(id: scheme_id[1..]).first
elsif location_id.present? elsif location_id.present?
joins(:locations).where("schemes.old_visible_id = ? AND locations.old_visible_id = ?", scheme_id.to_s, location_id.to_s).first || where(old_visible_id: scheme_id).first joins(:locations).where("ltrim(schemes.old_visible_id, '0') = ? AND ltrim(locations.old_visible_id, '0') = ?", scheme_id.to_s, location_id.to_s).first || where("ltrim(schemes.old_visible_id, '0') = ?", scheme_id.to_s).first
else else
where(old_visible_id: scheme_id).first where("ltrim(old_visible_id, '0') = ?", scheme_id.to_s).first
end end
end end

26
spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb

@ -1390,6 +1390,19 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
it "assigns the correct location" do it "assigns the correct location" do
expect(parser.log.location).to eql(location) expect(parser.log.location).to eql(location)
end end
context "when location had leading zeroes in its id in Old CORE" do
let(:attributes) { { bulk_upload:, field_4: scheme.old_visible_id, field_5: "123", field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
before do
location.old_visible_id = "00123"
location.save!
end
it "assigns the correct location" do
expect(parser.log.location).to eql(location)
end
end
end end
end end
@ -1408,6 +1421,19 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
it "assigns the correct scheme" do it "assigns the correct scheme" do
expect(parser.log.scheme).to eql(scheme) expect(parser.log.scheme).to eql(scheme)
end end
context "when scheme had leading zeroes in its id in Old CORE" do
let(:attributes) { { bulk_upload:, field_4: "10", field_5: location.old_visible_id, field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
before do
scheme.old_visible_id = "010"
scheme.save!
end
it "assigns the correct scheme" do
expect(parser.log.scheme).to eql(scheme)
end
end
end end
end end

27
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -1733,6 +1733,20 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
it "assigns the correct location" do it "assigns the correct location" do
expect(parser.log.location).to eql(location) expect(parser.log.location).to eql(location)
end end
context "when location had leading zeroes in its id in Old CORE" do
let(:attributes) { { bulk_upload:, field_15: scheme.old_visible_id, field_16: "123", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
before do
location.old_visible_id = "00123"
location.save!
end
it "assigns the correct location" do
expect(parser.log.location).to eql(location)
end
end
end end
end end
@ -1751,6 +1765,19 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
it "assigns the correct scheme" do it "assigns the correct scheme" do
expect(parser.log.scheme).to eql(scheme) expect(parser.log.scheme).to eql(scheme)
end end
context "when scheme had leading zeroes in its id in Old CORE" do
let(:attributes) { { bulk_upload:, field_15: "10", field_16: location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
before do
scheme.old_visible_id = "010"
scheme.save!
end
it "assigns the correct scheme" do
expect(parser.log.scheme).to eql(scheme)
end
end
end end
end end

Loading…
Cancel
Save