Browse Source

CLDC-3025 Fix leading zeroes bug in bulk upload (#2024)

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

* refactor: lint

* feat: also allow user to input extra leading zeroes and test

* refactor: lint
pull/2025/head
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
b712e1b502
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/location.rb
  2. 4
      app/models/scheme.rb
  3. 52
      spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb
  4. 52
      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_i.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_i.to_s, location_id.to_i.to_s).first || where("ltrim(schemes.old_visible_id, '0') = ?", scheme_id.to_i.to_s).first
else else
where(old_visible_id: scheme_id).first where("ltrim(old_visible_id, '0') = ?", scheme_id.to_i.to_s).first
end end
end end

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

@ -1390,6 +1390,32 @@ 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
context "when the user provides an id with leading zeroes" do
let(:attributes) { { bulk_upload:, field_4: scheme.old_visible_id, field_5: "00123", field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
before do
location.old_visible_id = "123"
location.save!
end
it "assigns the correct location" do
expect(parser.log.location).to eql(location)
end
end
end end
end end
@ -1408,6 +1434,32 @@ 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
context "when the user provides an id with leading zeroes" do
let(:attributes) { { bulk_upload:, field_4: "010", 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 = "10"
scheme.save!
end
it "assigns the correct scheme" do
expect(parser.log.scheme).to eql(scheme)
end
end
end end
end end

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

@ -1733,6 +1733,32 @@ 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
context "when the user provides an id with leading zeroes" do
let(:attributes) { { bulk_upload:, field_15: scheme.old_visible_id, field_16: "00123", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
before do
location.old_visible_id = "123"
location.save!
end
it "assigns the correct location" do
expect(parser.log.location).to eql(location)
end
end
end end
end end
@ -1751,6 +1777,32 @@ 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
context "when the user provides an id with leading zeroes" do
let(:attributes) { { bulk_upload:, field_15: "010", 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 = "10"
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