Browse Source

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

pull/2024/head
natdeanlewissoftwire 1 year ago
parent
commit
646c92ef5f
  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)
return if id.nil?
where(id:).or(where("ltrim(old_visible_id, '0') = ?", id.to_s)).first
where(id:).or(where("ltrim(old_visible_id, '0') = ?", id.to_i.to_s)).first
end
def postcode=(postcode)

4
app/models/scheme.rb

@ -169,9 +169,9 @@ class Scheme < ApplicationRecord
if scheme_id.start_with?("S")
where(id: scheme_id[1..]).first
elsif location_id.present?
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
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
where("ltrim(old_visible_id, '0') = ?", scheme_id.to_s).first
where("ltrim(old_visible_id, '0') = ?", scheme_id.to_i.to_s).first
end
end

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

@ -1403,6 +1403,19 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser 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
@ -1434,6 +1447,19 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser 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

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

@ -1746,6 +1746,20 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser 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
@ -1777,6 +1791,19 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser 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

Loading…
Cancel
Save