Browse Source

feat: undo work in validator(_spec)

cldc-1888-bulk-upload-duplicate-log-validation
Sam Seed 2 years ago
parent
commit
66e39732bb
  1. 13
      app/services/bulk_upload/lettings/validator.rb
  2. 21
      spec/services/bulk_upload/lettings/validator_spec.rb

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

@ -174,9 +174,8 @@ class BulkUpload::Lettings::Validator
end
def create_logs?
# return false if any_setup_sections_incomplete?
return false if any_setup_sections_incomplete?
return false if over_column_error_threshold?
return false if duplicate_log_already_exists?
row_parsers.all? { |row_parser| row_parser.log.valid? }
end
@ -204,16 +203,6 @@ private
end
end
def duplicate_log_already_exists?
fields = ["lettype", "beds"]
fields.all? do |field|
count = row_parsers.count { |row_parser| LettingsLog.where("#{field}": row_parser.attributes[field]).present? }
count > 0
end
end
def csv_parser
@csv_parser ||= BulkUpload::Lettings::CsvParser.new(path:)
end

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

@ -255,26 +255,5 @@ RSpec.describe BulkUpload::Lettings::Validator do
end
end
end
context "when the file contains a log which already exists in the db" do
let(:log_1) { create(:lettings_log, :completed, lettype: 7, beds: 3, created_by: user) } # DB
let(:log_2) { build(:lettings_log, :completed, lettype: 7, beds: 3, created_by: user) } # Bulk upload
before do
file.write(BulkUpload::LogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0).to_csv_row)
file.close
end
it "prevents log creation if there is a duplicate log" do
validator.call
expect(validator).not_to be_create_logs
end
it "allows log creation if there are no duplicate logs" do
log_1.update!(beds: 2)
validator.call
expect(validator).to be_create_logs
end
end
end
end

Loading…
Cancel
Save