Skip to content

Commit 5b2c54d

Browse files
misakathomasleese
authored andcommitted
Remove parse_rows! call from process!
This is to make it easier to reason about the code: when parse_rows! is explicit it's clear what stage of the process is executing when. Jira-Issue: MAV-6063
1 parent 9334518 commit 5b2c54d

8 files changed

Lines changed: 13 additions & 5 deletions

File tree

app/jobs/process_import_job.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ class ProcessImportJob < ApplicationJob
66
queue_as :imports
77

88
def perform(import)
9+
return if import.processed?
10+
911
SemanticLogger.tagged(import_id: import.id) do
1012
Sentry.set_tags(import_id: import.id)
1113

1214
import.parse_rows!
1315

16+
return if import.invalid?
1417
return if import.rows_are_invalid?
1518

1619
import.process!

app/models/concerns/csv_importable.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@ def processed?
146146
end
147147

148148
def process!
149-
return if processed?
150-
151-
parse_rows! if rows.nil?
152-
return if invalid?
153-
154149
process_import!
155150

156151
TeamCachedCounts.new(team).reset_import_issues!

spec/controllers/api/testing/teams_controller_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
create(:session, team:, location: team.gias_schools.first, programmes:)
4848

4949
process_and_approve_import(cohort_import)
50+
immunisation_import.parse_rows!
5051
immunisation_import.process!
5152

5253
Patient.find_each do |patient|

spec/models/class_import_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@
142142
queue: :imports
143143
).and_return(configured_job)
144144
allow(configured_job).to receive(:perform_later)
145+
146+
class_import.parse_rows!
145147
end
146148

147149
context "when pds_search_during_import flag is enabled" do

spec/models/cohort_import_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@
143143
queue: :imports
144144
).and_return(configured_job)
145145
allow(configured_job).to receive(:perform_later)
146+
147+
cohort_import.parse_rows!
146148
end
147149

148150
context "when pds_search_during_import flag is enabled" do

spec/models/immunisation_import_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@
197197
before do
198198
Flipper.enable(:pds)
199199
Flipper.enable(:pds_enqueue_bulk_updates)
200+
201+
immunisation_import.parse_rows!
200202
end
201203

202204
let(:duplicate_import) do

spec/support/imports_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def perform_enqueued_jobs_while_exists(only:)
4747
# Process and approve an import programmatically (for job/unit specs)
4848
# This simulates the full import flow including review and approval
4949
def process_and_approve_import(import)
50+
import.parse_rows!
5051
import.process!
5152

5253
unless import.is_a?(ImmunisationImport)

spec/support/shared_examples/a_csv_importable_model.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
describe "#process!" do
9292
let(:today) { Time.zone.local(2025, 6, 1) }
9393

94+
before { subject.parse_rows! }
95+
9496
# TODO: Remove if ... when ImmunisationImport's implementation has been
9597
# updated to match the others (i.e. it uses changesets)
9698
if described_class <= ImmunisationImport

0 commit comments

Comments
 (0)