Browse Source

Validate also content of rows

pull/1795/head
Jack S 3 years ago
parent
commit
3c759a7bf6
  1. 2
      app/services/bulk_upload/lettings/validator.rb
  2. 2
      app/services/bulk_upload/sales/validator.rb
  3. 12
      spec/services/bulk_upload/lettings/validator_spec.rb
  4. 12
      spec/services/bulk_upload/sales/validator_spec.rb

2
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!

2
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!

12
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(","))

12
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(","))

Loading…
Cancel
Save