Browse Source

fix which row bulk upload error belongs to (#1192)

pull/1175/head
Phil Lee 2 years ago committed by GitHub
parent
commit
21eb2d5511
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/services/bulk_upload/lettings/validator.rb
  2. 9
      spec/services/bulk_upload/lettings/validator_spec.rb

4
app/services/bulk_upload/lettings/validator.rb

@ -154,7 +154,7 @@ class BulkUpload::Lettings::Validator
row_parsers.each_with_index do |row_parser, index| row_parsers.each_with_index do |row_parser, index|
row_parser.valid? row_parser.valid?
row = index + row_offset row = index + row_offset + 1
row_parser.errors.each do |error| row_parser.errors.each do |error|
bulk_upload.bulk_upload_errors.create!( bulk_upload.bulk_upload_errors.create!(
@ -163,7 +163,7 @@ class BulkUpload::Lettings::Validator
tenant_code: row_parser.field_7, tenant_code: row_parser.field_7,
property_ref: row_parser.field_100, property_ref: row_parser.field_100,
row:, row:,
cell: "#{cols[field_number_for_attribute(error.attribute) - col_offset + 1]}#{row + 1}", cell: "#{cols[field_number_for_attribute(error.attribute) - col_offset + 1]}#{row}",
) )
end end
end end

9
spec/services/bulk_upload/lettings/validator_spec.rb

@ -32,8 +32,15 @@ RSpec.describe BulkUpload::Lettings::Validator do
context "when a valid csv" do context "when a valid csv" do
let(:path) { file_fixture("2022_23_lettings_bulk_upload.csv") } let(:path) { file_fixture("2022_23_lettings_bulk_upload.csv") }
it do it "creates validation errors" do
expect { validator.call }.to change(BulkUploadError, :count)
end
it "create validation error with correct values" do
validator.call validator.call
error = BulkUploadError.first
expect(error.row).to eq("6")
end end
end end
end end

Loading…
Cancel
Save