Skip to content

Commit 3f6e39d

Browse files
Add tests
1 parent 4d88a6c commit 3f6e39d

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

spec/models/class_import_row_spec.rb

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@
327327
end
328328
end
329329

330-
context "with an existing patient already with an address" do
330+
context "with an existing patient already with an address (with a different postcode)" do
331331
let(:data) do
332332
valid_data.merge(
333333
"CHILD_ADDRESS_LINE_1" => "10 Downing Street",
@@ -373,6 +373,49 @@
373373
)
374374
end
375375
end
376+
377+
context "with an existing patient already with an address (with the same postcode)" do
378+
let(:data) do
379+
valid_data.merge(
380+
"CHILD_ADDRESS_LINE_1" => "10 Downing Street",
381+
"CHILD_ADDRESS_LINE_2" => "",
382+
"CHILD_TOWN" => "London",
383+
"CHILD_POSTCODE" => "SW1A 1AA"
384+
)
385+
end
386+
387+
let!(:existing_patient) do
388+
create(
389+
:patient,
390+
family_name: "Smith",
391+
gender_code: "male",
392+
given_name: "Jimmy",
393+
nhs_number: "9990000018",
394+
address_line_1: "20 Woodstock Road",
395+
address_line_2: "",
396+
address_town: "Oxford",
397+
address_postcode: "SW1A 1AA",
398+
birth_academic_year: 2009,
399+
date_of_birth: Date.new(2010, 1, 1),
400+
registration: "8AB"
401+
)
402+
end
403+
404+
it { should eq(existing_patient) }
405+
406+
it "does save the incoming address" do
407+
expect(patient).to have_attributes(
408+
address_line_1: "10 Downing Street",
409+
address_line_2: "",
410+
address_town: "London",
411+
address_postcode: "SW1A 1AA"
412+
)
413+
end
414+
415+
it "doesn't stage the address differences" do
416+
expect(patient.pending_changes).to be_empty
417+
end
418+
end
376419
end
377420

378421
describe "#to_parent_relationships" do

spec/models/cohort_import_row_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,40 @@
325325
end
326326
end
327327

328+
context "with an existing patient with a different address (but matching postcode)" do
329+
let!(:existing_patient) do
330+
create(
331+
:patient,
332+
family_name: "Smith",
333+
given_name: "Jimmy",
334+
gender_code: "male",
335+
nhs_number: "9990000018",
336+
birth_academic_year: 2009,
337+
date_of_birth: Date.new(2010, 1, 1),
338+
registration: "8AB",
339+
address_line_1: "15 Woodstock Road",
340+
address_line_2: "Jericho",
341+
address_town: "Oxford",
342+
address_postcode: "SW1A 1AA"
343+
)
344+
end
345+
346+
it { should eq(existing_patient) }
347+
348+
it "saves the incoming address" do
349+
expect(patient).to have_attributes(
350+
address_line_1: "10 Downing Street",
351+
address_line_2: "",
352+
address_town: "London",
353+
address_postcode: "SW1A 1AA"
354+
)
355+
end
356+
357+
it "doesn't stage the incoming address" do
358+
expect(patient.pending_changes).to be_empty
359+
end
360+
end
361+
328362
context "with an existing patient already with an address" do
329363
let!(:existing_patient) do
330364
create(

0 commit comments

Comments
 (0)