Skip to content

Commit 0b99660

Browse files
misakathomasleese
authored andcommitted
Make csv= specs actually test something
Recent changes rewired specs to test import by setting `csv_data` instead of `csv` to isolate what's being tested, but that left `csv=` largely being untested. Jira-Issue: MAV-6063
1 parent 0d2615d commit 0b99660

6 files changed

Lines changed: 35 additions & 20 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CHILD_FIRST_NAME,CHILD_LAST_NAME,CHILD_DATE_OF_BIRTH,CHILD_POSTCODE,CHILD_SCHOOL_URN
2+
Jennifer,Clarke,2010-01-01,SW1A 1AA,123456
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ORGANISATION_CODE,SCHOOL_URN,SCHOOL_NAME,NHS_NUMBER,PERSON_FORENAME,PERSON_SURNAME,PERSON_DOB,PERSON_GENDER_CODE,PERSON_POSTCODE,VACCINATED,DATE_OF_VACCINATION,PROGRAMME,VACCINE_GIVEN,BATCH_NUMBER,BATCH_EXPIRY_DATE,ANATOMICAL_SITE,PERFORMING_PROFESSIONAL_FORENAME,PERFORMING_PROFESSIONAL_SURNAME,REASON_NOT_VACCINATED,CONSENT_TYPE,LOCAL_PATIENT_ID,LOCAL_PATIENT_ID_URI
2+
R1L,120026,shaftesbury junior school ,7420180008,Chyna,Pickle,20120912,Not Specified,LE3 2DA,Yes,20250514,Flu,,123013325,20220730,Left Buttock,Vaccinator1,Name1,,Parental Consent,LocalPatient1,www.LocalPatient1

spec/models/class_import_spec.rb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
let(:session) { create(:session, location:, programmes:, team:) }
4949

5050
let(:file) { "valid.csv" }
51-
let(:csv_data) { file_fixture("class_import/#{file}").read }
51+
let(:csv_source) { file_fixture("class_import/#{file}") }
52+
let(:csv_data) { csv_source.read }
53+
# Used by shared examples in CSVImportable to test setting csv from an uploaded file
5254
let(:uploaded_csv_file) { nil }
5355

5456
# This is used by validation tests in the CSFVImportable shared specs.
@@ -61,18 +63,6 @@
6163

6264
before { parse_rows! }
6365

64-
describe "with a BOM" do
65-
let(:csv_data) { nil }
66-
let(:uploaded_csv_file) do
67-
fixture_file_upload("class_import/#{file}", filename: file)
68-
end
69-
let(:file) { "valid_with_bom.csv" }
70-
71-
it "removes the BOM" do
72-
expect(class_import).to be_valid
73-
end
74-
end
75-
7666
describe "with invalid fields" do
7767
let(:file) { "invalid_fields.csv" }
7868

spec/models/cohort_import_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
let(:team) { create(:team, programmes:) }
4343

4444
let(:file) { "valid.csv" }
45-
let(:csv_data) { file_fixture("cohort_import/#{file}").read }
45+
let(:csv_source) { file_fixture("cohort_import/#{file}") }
46+
let(:csv_data) { csv_source.read }
47+
# Used by shared examples in CSVImportable to test setting csv from an uploaded file
4648
let(:uploaded_csv_file) { nil }
4749

4850
# Ensure location URN matches the URN in our fixture files

spec/models/immunisation_import_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@
3535

3636
describe ImmunisationImport do
3737
subject(:immunisation_import) do
38-
create(:immunisation_import, team:, csv_data:, uploaded_by:)
38+
create(
39+
:immunisation_import,
40+
team:,
41+
csv_data:,
42+
uploaded_by:,
43+
uploaded_csv_file:
44+
)
3945
end
4046

4147
before do
@@ -56,7 +62,9 @@
5662
let(:school) { create(:gias_school, urn: "123456") }
5763

5864
let(:file) { "valid_flu.csv" }
59-
let(:csv_data) { file_fixture("immunisation_import/#{type}/#{file}").read }
65+
let(:csv_source) { file_fixture("immunisation_import/#{type}/#{file}") }
66+
let(:csv_data) { csv_source.read }
67+
# Used by shared examples in CSVImportable to test setting csv from an uploaded file
6068
let(:uploaded_csv_file) { nil }
6169
let(:uploaded_by) { create(:user, team:) }
6270

spec/support/shared_examples/a_csv_importable_model.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,26 @@
5151
end
5252
end
5353

54-
# TODO: This needs to set `csv`, it currently doesn't trigger it the way it's
55-
# done here.
5654
describe "#csv=" do
55+
let(:csv_data) { nil }
56+
let(:uploaded_csv_file) { fixture_file_upload(csv_source) }
57+
5758
it "sets the data" do
58-
expect(subject.csv_data).not_to be_empty
59+
expect(subject.csv_data).to eq uploaded_csv_file.read
5960
end
6061

6162
it "sets the filename" do
62-
expect(subject.csv_filename).not_to be_empty
63+
expect(subject.csv_filename).to eq uploaded_csv_file.original_filename
64+
end
65+
66+
context "with a payload with a BOM" do
67+
# This requires that each test using these shared example have a file with
68+
# a BOM in their fixtures directory
69+
let(:file) { "valid_with_bom.csv" }
70+
71+
it "results in a valid import" do
72+
expect(subject).to be_valid
73+
end
6374
end
6475
end
6576

0 commit comments

Comments
 (0)