diff --git a/app/services/bulk_upload/lettings/validator.rb b/app/services/bulk_upload/lettings/validator.rb index 4ca989f31..7db10a27c 100644 --- a/app/services/bulk_upload/lettings/validator.rb +++ b/app/services/bulk_upload/lettings/validator.rb @@ -144,7 +144,7 @@ private end def validate_file_not_empty - if File.size(path).zero? || csv_parser.row_parsers.empty? + if File.size(path).zero? || csv_parser.body_rows.flatten.empty? errors.add(:base, :blank_file) halt_validations! diff --git a/app/services/bulk_upload/sales/validator.rb b/app/services/bulk_upload/sales/validator.rb index f15965603..3c3e7d71c 100644 --- a/app/services/bulk_upload/sales/validator.rb +++ b/app/services/bulk_upload/sales/validator.rb @@ -138,7 +138,7 @@ private end def validate_file_not_empty - if File.size(path).zero? || csv_parser.row_parsers.empty? + if File.size(path).zero? || csv_parser.body_rows.flatten.empty? errors.add(:base, :blank_file) halt_validations! diff --git a/spec/services/bulk_upload/lettings/validator_spec.rb b/spec/services/bulk_upload/lettings/validator_spec.rb index a2d3d1b6a..595192210 100644 --- a/spec/services/bulk_upload/lettings/validator_spec.rb +++ b/spec/services/bulk_upload/lettings/validator_spec.rb @@ -35,6 +35,18 @@ RSpec.describe BulkUpload::Lettings::Validator do end end + context "and has a new line in it (empty)" do + before do + file.write("\n") + file.rewind + end + + it "is not valid" do + expect(validator).not_to be_valid + expect(validator.errors["base"]).to eql(["Template is blank - The template must be filled in for us to create the logs and check if data is correct."]) + end + end + context "and doesn't have too many columns" do before do file.write(("a" * 95).chars.join(",")) diff --git a/spec/services/bulk_upload/sales/validator_spec.rb b/spec/services/bulk_upload/sales/validator_spec.rb index d7e254864..165abf8df 100644 --- a/spec/services/bulk_upload/sales/validator_spec.rb +++ b/spec/services/bulk_upload/sales/validator_spec.rb @@ -17,6 +17,18 @@ RSpec.describe BulkUpload::Sales::Validator do end end + context "and has a new line in it (empty)" do + before do + file.write("\n") + file.rewind + end + + it "is not valid" do + expect(validator).not_to be_valid + expect(validator.errors["base"]).to eql(["Template is blank - The template must be filled in for us to create the logs and check if data is correct."]) + end + end + context "when file has too many columns" do before do file.write((%w[a] * 127).join(","))