Skip to content

Commit

Permalink
reflect csv row count when skipped rows
Browse files Browse the repository at this point in the history
  • Loading branch information
asmega committed Oct 16, 2024
1 parent c37723c commit 7d29097
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/eligible_fe_providers_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(file, academic_year)
end

def results_message
"Replaced #{deleted_row_count} existing providers with #{rows.count} new providers"
"Replaced #{deleted_row_count} existing providers with #{rows_with_data_count} new providers"
end

private
Expand Down
13 changes: 10 additions & 3 deletions lib/csv_importer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ module CsvImporter
class Base
include CsvImporter::Config

attr_reader :errors, :rows, :deleted_row_count
attr_reader :errors, :rows, :deleted_row_count, :skipped_row_count

def initialize(file)
@errors = []
@rows = parse_csv_file(file)
@deleted_row_count = 0
@skipped_row_count = 0

check_headers if rows && with_headers?
end
Expand All @@ -21,8 +22,10 @@ def run
Rails.logger.info "Processing #{target_data_model.to_s.titleize} batch #{i}"

record_hashes = batch_rows.map do |row|
next if empty_row?(row)
next if valid_skip_row_conditions?(row)
if empty_row?(row) || valid_skip_row_conditions?(row)
@skipped_row_count += 1
next
end

convert_row_to_hash(row)
end.compact
Expand All @@ -31,6 +34,10 @@ def run
end
end

def rows_with_data_count
rows.count - skipped_row_count
end

private

def empty_row?(row)
Expand Down
6 changes: 6 additions & 0 deletions spec/models/eligible_fe_providers_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def to_row(hash)
it "does not raise errors" do
expect { subject.run }.not_to raise_error
end

it "returns correct rows_with_data_count" do
subject.run

expect(subject.rows_with_data_count).to eql(3)
end
end

context "with valid data" do
Expand Down

0 comments on commit 7d29097

Please sign in to comment.