diff --git a/app/services/candidates/registrations/subject_and_date_information.rb b/app/services/candidates/registrations/subject_and_date_information.rb index 8968055b11..803911ac69 100644 --- a/app/services/candidates/registrations/subject_and_date_information.rb +++ b/app/services/candidates/registrations/subject_and_date_information.rb @@ -16,14 +16,11 @@ def placement_date end def placement_date_subject - @placement_date_subject ||= Bookings::PlacementDateSubject.find_by( - bookings_placement_date_id: bookings_placement_date_id, - bookings_subject_id: bookings_subject_id - ) + @placement_date_subject ||= find_placement_date_subject end def bookings_subject - @bookings_subject ||= Bookings::Subject.find_by(id: bookings_subject_id) + @bookings_subject ||= find_bookings_subject end def date_and_subject_ids @@ -73,6 +70,19 @@ def secondary_placement_dates_grouped_by_date .flatten .group_by(&:date) end + + private + + def find_placement_date_subject + Bookings::PlacementDateSubject + .joins(:bookings_subject) + .where(bookings_placement_date_id: bookings_placement_date_id, bookings_subjects: { id: bookings_subject_id, hidden: false }) + .first + end + + def find_bookings_subject + Bookings::Subject.find_by(id: bookings_subject_id, hidden: false) + end end end end diff --git a/db/data/subjects.yml b/db/data/subjects.yml index ab6d1ff34e..3bfc7a1fa2 100644 --- a/db/data/subjects.yml +++ b/db/data/subjects.yml @@ -21,10 +21,8 @@ - Music - Physical Education - Physics -- Physics with maths - Primary - Psychology - Religious Education - Social Sciences - Spanish -- Vocational health diff --git a/spec/services/candidates/registrations/subject_and_date_information_spec.rb b/spec/services/candidates/registrations/subject_and_date_information_spec.rb index e934a9cff1..d8bc6c2451 100644 --- a/spec/services/candidates/registrations/subject_and_date_information_spec.rb +++ b/spec/services/candidates/registrations/subject_and_date_information_spec.rb @@ -105,14 +105,11 @@ subject.bookings_subject_id = 2 end - before { allow(Bookings::PlacementDateSubject).to receive(:find_by).and_return('a') } + before { allow(subject).to receive(:find_placement_date_subject).and_return('a') } specify 'should find the placement date via its id' do subject.placement_date_subject - expect(Bookings::PlacementDateSubject).to have_received(:find_by).with( - bookings_placement_date_id: 1, - bookings_subject_id: 2 - ) + expect(subject).to have_received(:find_placement_date_subject) end end