Skip to content

Commit 011a484

Browse files
authored
Merge pull request #6461 from NHSDigital/seed-without-school-moves
Update school move factories
2 parents f4eab77 + 40c2cec commit 011a484

4 files changed

Lines changed: 10 additions & 76 deletions

File tree

spec/factories/school_moves.rb

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,31 @@
2929
#
3030
FactoryBot.define do
3131
factory :school_move do
32+
transient { team { nil } }
33+
3234
patient
3335

3436
academic_year { AcademicYear.pending }
3537
source { SchoolMove.sources.keys.sample }
3638

3739
trait :to_school do
38-
home_educated { nil }
39-
team { nil }
4040
school
4141
end
4242

4343
trait :to_home_educated do
44-
home_educated { true }
45-
team
46-
school { nil }
44+
team { create(:team) }
45+
school { team.home_educated_school }
4746
end
4847

4948
trait :to_unknown_school do
50-
home_educated { false }
51-
team
52-
school { nil }
49+
team { create(:team) }
50+
school { team.unknown_school }
5351
end
5452

5553
after(:create) do |school_move|
56-
team_scope =
57-
if (id = school_move.team_id)
58-
Team.where(id:)
59-
else
60-
school_move.school.teams
61-
end
62-
6354
PatientTeamUpdater.call(
6455
patient_scope: Patient.where(id: school_move.patient_id),
65-
team_scope:
56+
team_scope: school_move.school.teams
6657
)
6758
end
6859
end

spec/lib/patient_team_updater_spec.rb

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
end
2929
end
3030

31-
context "with a school move by school" do
31+
context "with a school move" do
3232
before do
3333
create(
3434
:school_move,
@@ -48,19 +48,6 @@
4848
end
4949
end
5050

51-
context "with a school move by team" do
52-
before do
53-
create(:school_move, :to_home_educated, patient:, team:)
54-
PatientTeam.delete_all
55-
end
56-
57-
it "adds the patient to the team" do
58-
expect(patient.teams).to be_empty
59-
expect { call }.to change(PatientTeam, :count).by(1)
60-
expect(PatientTeam.last.sources).to contain_exactly("school_move_team")
61-
end
62-
end
63-
6451
context "with a vaccination record by import" do
6552
before do
6653
create(

spec/models/patient_spec.rb

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@
13101310
end
13111311
end
13121312

1313-
context "when the old patient has a school move to a school" do
1313+
context "when the old patient has school moves" do
13141314
let(:team) { create(:team) }
13151315
let(:school) { create(:school, team:) }
13161316

@@ -1329,48 +1329,6 @@
13291329
)
13301330
end
13311331
end
1332-
1333-
context "when the old patient has a school move to an unknown school" do
1334-
let(:team) { create(:team) }
1335-
1336-
before do
1337-
create(:school_move, :to_unknown_school, patient: old_patient, team:)
1338-
end
1339-
1340-
it "adds any school moves from the old patient" do
1341-
expect(new_patient.school_moves.size).to eq(1)
1342-
expect(new_patient.school_moves.first.home_educated).to be(false)
1343-
end
1344-
1345-
it "adds the new patient to the teams" do
1346-
expect(new_patient.patient_teams.size).to eq(1)
1347-
expect(new_patient.patient_teams.first.team_id).to eq(team.id)
1348-
expect(new_patient.patient_teams.first.sources).to contain_exactly(
1349-
"school_move_team"
1350-
)
1351-
end
1352-
end
1353-
1354-
context "when the old patient has a school move to home-schooled" do
1355-
let(:team) { create(:team) }
1356-
1357-
before do
1358-
create(:school_move, :to_home_educated, patient: old_patient, team:)
1359-
end
1360-
1361-
it "adds any school moves from the old patient" do
1362-
expect(new_patient.school_moves.size).to eq(1)
1363-
expect(new_patient.school_moves.first.home_educated).to be(true)
1364-
end
1365-
1366-
it "adds the new patient to the teams" do
1367-
expect(new_patient.patient_teams.size).to eq(1)
1368-
expect(new_patient.patient_teams.first.team_id).to eq(team.id)
1369-
expect(new_patient.patient_teams.first.sources).to contain_exactly(
1370-
"school_move_team"
1371-
)
1372-
end
1373-
end
13741332
end
13751333

13761334
describe "#destroy_childless_parents" do

spec/models/school_move_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@
9999

100100
shared_examples "sets the patient to home-schooled" do
101101
it "sets the patient to home-schooled" do
102-
expect { confirm! }.to change(patient, :school).to(
103-
school_move.team.home_educated_school
104-
)
102+
expect { confirm! }.to change(patient, :school).to(school_move.school)
105103
end
106104
end
107105

0 commit comments

Comments
 (0)