Browse Source

persist expected log count

bulk-upload-resume
Phil Lee 2 years ago
parent
commit
23f5e4be5b
  1. 10
      app/services/bulk_upload/lettings/validator.rb
  2. 5
      db/migrate/20230320163945_add_expected_log_count.rb
  3. 3
      db/schema.rb
  4. 4
      spec/services/bulk_upload/lettings/validator_spec.rb

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

@ -38,6 +38,8 @@ class BulkUpload::Lettings::Validator
)
end
end
update_expected_log_count
end
def create_logs?
@ -62,6 +64,14 @@ class BulkUpload::Lettings::Validator
private
def update_expected_log_count
bulk_upload.update!(expected_log_count:)
end
def expected_log_count
row_parsers.count { |row| !row.blank_row? }
end
def over_column_error_threshold?
fields = ("field_1".."field_134").to_a
percentage_threshold = (row_parsers.size * COLUMN_PERCENTAGE_ERROR_THRESHOLD).ceil

5
db/migrate/20230320163945_add_expected_log_count.rb

@ -0,0 +1,5 @@
class AddExpectedLogCount < ActiveRecord::Migration[7.0]
def change
add_column :bulk_uploads, :expected_log_count, :integer
end
end

3
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_03_20_084057) do
ActiveRecord::Schema[7.0].define(version: 2023_03_20_163945) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -39,6 +39,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_20_084057) do
t.datetime "updated_at", null: false
t.text "filename"
t.integer "needstype"
t.integer "expected_log_count"
t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true
t.index ["user_id"], name: "index_bulk_uploads_on_user_id"
end

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

@ -69,6 +69,10 @@ RSpec.describe BulkUpload::Lettings::Validator do
expect(error.category).to eql("setup")
end
it "updates expected_log_count" do
expect { validator.call }.to change(bulk_upload, :expected_log_count).from(nil).to(3)
end
end
context "with arbitrary ordered 23/24 csv" do

Loading…
Cancel
Save