Skip to content

Commit 9334518

Browse files
misakathomasleese
authored andcommitted
Refactor rspec subjects to be import objects
This changes import specs to not make test `subject` an action. This is stylistic, it can work either way, but considering how hard it's been to reason about the imports I thought it would be better to return to what's considered common convention to try to make the tests easier to understand. This became particularly apparent when a call to `parse_rows!` had to be added to tests (coming in a later change), meaning the `subject` would need a call to `parse_rows!`, or possibly `parse_rows!` added to the `before` block, but either way it was becoming un-idiomatic. Jira-Issue: MAV-6063
1 parent 0b99660 commit 9334518

3 files changed

Lines changed: 61 additions & 71 deletions

File tree

spec/models/class_import_spec.rb

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@
5959
it_behaves_like "a CSVImportable model"
6060

6161
describe "#parse_rows!" do
62-
subject(:parse_rows!) { class_import.parse_rows! }
63-
64-
before { parse_rows! }
62+
before { class_import.parse_rows! }
6563

6664
describe "with invalid fields" do
6765
let(:file) { "invalid_fields.csv" }
@@ -136,8 +134,6 @@
136134
end
137135

138136
describe "#process!" do
139-
subject(:process!) { class_import.process! }
140-
141137
let(:file) { "valid.csv" }
142138
let(:configured_job) { instance_double(ActiveJob::ConfiguredJob) }
143139

@@ -155,7 +151,7 @@
155151
end
156152

157153
it "enqueues PDSCascadingSearchJob for each changeset with a postcode" do
158-
process!
154+
class_import.process!
159155

160156
expect(configured_job).to have_received(:perform_later).exactly(3).times
161157
without_postcode =
@@ -172,7 +168,7 @@
172168
before { Flipper.disable(:pds_search_during_import) }
173169

174170
it "enqueues ReviewPatientChangesetJob for each changeset" do
175-
expect { process! }.to have_enqueued_job(
171+
expect { class_import.process! }.to have_enqueued_job(
176172
ReviewPatientChangesetJob
177173
).exactly(4).times
178174

@@ -227,8 +223,6 @@
227223
end
228224

229225
describe "#validate_pds_match_rate!" do
230-
subject(:validate_pds_match_rate!) { class_import.validate_pds_match_rate! }
231-
232226
context "when match rate is equal to threshold" do
233227
before do
234228
create_list(
@@ -241,7 +235,7 @@
241235
end
242236

243237
it "does not mark as low_pds_match_rate" do
244-
validate_pds_match_rate!
238+
class_import.validate_pds_match_rate!
245239
expect(class_import.reload.status).not_to eq("low_pds_match_rate")
246240
end
247241
end
@@ -258,7 +252,7 @@
258252
end
259253

260254
it "marks the import as low_pds_match_rate" do
261-
validate_pds_match_rate!
255+
class_import.validate_pds_match_rate!
262256
expect(class_import.reload.status).to eq("low_pds_match_rate")
263257
end
264258
end
@@ -267,22 +261,18 @@
267261
before { create_list(:patient_changeset, 5, import: class_import) }
268262

269263
it "skips validation" do
270-
validate_pds_match_rate!
264+
class_import.validate_pds_match_rate!
271265
expect(class_import.reload.status).not_to eq("low_pds_match_rate")
272266
end
273267
end
274268
end
275269

276270
describe "#validate_changeset_uniqueness!" do
277-
subject(:validate_changeset_uniqueness!) do
278-
class_import.validate_changeset_uniqueness!
279-
end
280-
281271
context "when all rows are unique" do
282272
before { create_list(:patient_changeset, 3, import: class_import) }
283273

284274
it "does not mark the import as changesets_are_invalid" do
285-
validate_changeset_uniqueness!
275+
class_import.validate_changeset_uniqueness!
286276
expect(class_import.reload.status).not_to eq("changesets_are_invalid")
287277
expect(class_import.serialized_errors).to be_nil.or eq({})
288278
end
@@ -316,7 +306,7 @@
316306
end
317307

318308
it "marks the import as changesets_are_invalid and records errors" do
319-
validate_changeset_uniqueness!
309+
class_import.validate_changeset_uniqueness!
320310

321311
expect(class_import.reload.status).to eq("changesets_are_invalid")
322312
expect(class_import.serialized_errors.values.flatten).to include(
@@ -333,7 +323,7 @@
333323
end
334324

335325
it "marks the import as changesets_are_invalid and includes Mavis duplicate error" do
336-
validate_changeset_uniqueness!
326+
class_import.validate_changeset_uniqueness!
337327

338328
expect(class_import.reload.status).to eq("changesets_are_invalid")
339329
expect(class_import.serialized_errors.values.flatten).to include(

spec/models/cohort_import_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@
5656
it_behaves_like "a CSVImportable model"
5757

5858
describe "#parse_rows!" do
59-
subject(:parse_rows!) { cohort_import.parse_rows! }
60-
61-
before { parse_rows! }
59+
before { cohort_import.parse_rows! }
6260

6361
describe "with invalid fields" do
6462
let(:file) { "invalid_fields.csv" }
@@ -137,8 +135,6 @@
137135
end
138136

139137
describe "#process!" do
140-
subject(:process!) { cohort_import.process! }
141-
142138
let(:configured_job) { instance_double(ActiveJob::ConfiguredJob) }
143139
let(:file) { "valid.csv" }
144140

@@ -156,7 +152,7 @@
156152
end
157153

158154
it "enqueues PDSCascadingSearchJob for each changeset" do
159-
process!
155+
cohort_import.process!
160156

161157
expect(configured_job).to have_received(:perform_later).exactly(3).times
162158
end
@@ -166,7 +162,7 @@
166162
before { Flipper.disable(:pds_search_during_import) }
167163

168164
it "enqueues ReviewPatientChangesetJob for each changeset" do
169-
expect { process! }.to have_enqueued_job(
165+
expect { cohort_import.process! }.to have_enqueued_job(
170166
ReviewPatientChangesetJob
171167
).exactly(3).times
172168
end

0 commit comments

Comments
 (0)