diff --git a/spec/controllers/concerns/patient_tabs_concern_spec.rb b/spec/controllers/concerns/patient_tabs_concern_spec.rb index fe60c6334..8ddcacd3a 100644 --- a/spec/controllers/concerns/patient_tabs_concern_spec.rb +++ b/spec/controllers/concerns/patient_tabs_concern_spec.rb @@ -164,12 +164,14 @@ end context "some of the groups are empty" do - let(:patient_session) { create(:patient_session, :consent_refused) } + let(:patient_sessions) do + create_list(:patient_session, 1, :consent_refused) + end it "returns an empty array for all the empty groups" do result = controller.group_patient_sessions_by_state( - [patient_session], + patient_sessions, section: :triage ) @@ -177,7 +179,7 @@ { needs_triage: [], triage_complete: [], - no_triage_needed: [patient_session] + no_triage_needed: patient_sessions }.with_indifferent_access ) end diff --git a/spec/lib/unscheduled_sessions_factory_spec.rb b/spec/lib/unscheduled_sessions_factory_spec.rb index 2c2b80f95..88324f603 100644 --- a/spec/lib/unscheduled_sessions_factory_spec.rb +++ b/spec/lib/unscheduled_sessions_factory_spec.rb @@ -13,7 +13,7 @@ it "creates missing unscheduled sessions" do expect { call }.to change(organisation.sessions, :count).by(1) - session = organisation.sessions.first + session = organisation.sessions.includes(:location, :programmes).first expect(session.location).to eq(location) expect(session.programmes).to eq([programme]) end @@ -25,7 +25,7 @@ it "creates missing unscheduled sessions" do expect { call }.to change(organisation.sessions, :count).by(1) - session = organisation.sessions.first + session = organisation.sessions.includes(:location, :programmes).first expect(session.location).to eq(location) expect(session.programmes).to eq([programme]) end diff --git a/spec/models/class_import_spec.rb b/spec/models/class_import_spec.rb index 042eaa754..ab0566f36 100644 --- a/spec/models/class_import_spec.rb +++ b/spec/models/class_import_spec.rb @@ -316,7 +316,7 @@ expect { process! }.to change(Parent, :count).by(4) parent_relationship = patient.reload.parent_relationships.first - expect(parent_relationship.parent).to eq(parent) + expect(parent_relationship.parent_id).to eq(parent.id) expect(parent_relationship).to be_father end end @@ -351,7 +351,7 @@ ) school_move = patient.school_moves.first - expect(school_move.school).to eq(session.location) + expect(school_move.school_id).to eq(session.location_id) end it "doesn't stage school changes" do diff --git a/spec/models/consent_form_spec.rb b/spec/models/consent_form_spec.rb index d51f39a1e..784e498a9 100644 --- a/spec/models/consent_form_spec.rb +++ b/spec/models/consent_form_spec.rb @@ -773,7 +773,7 @@ ).by(1) school_move = patient.school_moves.first - expect(school_move.school).to eq(new_school) + expect(school_move.school_id).to eq(new_school.id) end end diff --git a/spec/models/immunisation_import_spec.rb b/spec/models/immunisation_import_spec.rb index 2366c231d..c2730f9e4 100644 --- a/spec/models/immunisation_import_spec.rb +++ b/spec/models/immunisation_import_spec.rb @@ -243,7 +243,7 @@ expect(immunisation_import.sessions.count).to eq(5) - session = immunisation_import.sessions.first + session = immunisation_import.sessions.includes(:session_dates).first expect(session.dates).to contain_exactly(Date.new(2024, 5, 14)) end diff --git a/spec/models/onboarding_spec.rb b/spec/models/onboarding_spec.rb index 01b1e954d..461ba5b5d 100644 --- a/spec/models/onboarding_spec.rb +++ b/spec/models/onboarding_spec.rb @@ -28,11 +28,11 @@ expect(organisation.careplus_venue_code).to eq("EXAMPLE") expect(organisation.programmes).to contain_exactly(programme) - team1 = organisation.teams.find_by!(name: "Team 1") + team1 = organisation.teams.includes(:schools).find_by!(name: "Team 1") expect(team1.email).to eq("team-1@trust.nhs.uk") expect(team1.phone).to eq("07700 900816") - team2 = organisation.teams.find_by!(name: "Team 2") + team2 = organisation.teams.includes(:schools).find_by!(name: "Team 2") expect(team2.email).to eq("team-2@trust.nhs.uk") expect(team2.phone).to eq("07700 900817") diff --git a/spec/models/patient_session_stats_spec.rb b/spec/models/patient_session_stats_spec.rb index 1c36a7119..a175d5519 100644 --- a/spec/models/patient_session_stats_spec.rb +++ b/spec/models/patient_session_stats_spec.rb @@ -2,7 +2,9 @@ describe PatientSessionStats do describe "#to_h" do - subject(:to_h) { described_class.new(session.patient_sessions).to_h } + subject(:to_h) do + described_class.new(session.patient_sessions.preload_for_status).to_h + end let(:programme) { create(:programme) } let(:session) { create(:session, programme:) } diff --git a/spec/models/triage_spec.rb b/spec/models/triage_spec.rb index e19345e30..3d51b8957 100644 --- a/spec/models/triage_spec.rb +++ b/spec/models/triage_spec.rb @@ -73,14 +73,11 @@ let(:status) { :delay_vaccination } it "adds the patient to the generic clinic" do - expect { process! }.to change( - triage.patient.upcoming_sessions, - :count - ).by(1) + upcoming_sessions = triage.patient.upcoming_sessions.includes(:location) - expect( - triage.patient.upcoming_sessions.last.location - ).to be_generic_clinic + expect { process! }.to change(upcoming_sessions, :count).by(1) + + expect(upcoming_sessions.last.location).to be_generic_clinic end end end