Skip to content

Commit

Permalink
Refactor subject and date information retrieval in Candidates::Regist…
Browse files Browse the repository at this point in the history
…rations::SubjectAndDateInformation.rb (#3169)

* Exclude hidden subjects from `placement_date_subjects` query
*Refactor `#placement_date_subject` in `subject_and_date_information.rb` to use `find_placement_date_subject` method
*  update specs to reflect changes to the model
  • Loading branch information
ekumachidi authored Apr 26, 2024
1 parent c42a1f2 commit d48929a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions db/data/subjects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
- Music
- Physical Education
- Physics
- Physics with maths
- Primary
- Psychology
- Religious Education
- Social Sciences
- Spanish
- Vocational health
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d48929a

Please sign in to comment.