Skip to content

Commit

Permalink
Add test for when course.enrichments are not loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
inulty-dfe committed Oct 30, 2024
1 parent b04af8d commit c542ae3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 0 additions & 1 deletion app/models/required_qualifications_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def initialize(course)
end

def extract
# This performance improvement saves ~100 database queries in the courses api endpoint
legacy_qualifications_attribute = if course.enrichments.loaded?
course.enrichments.max_by(&:created_at)&.required_qualifications
else
Expand Down
12 changes: 12 additions & 0 deletions spec/models/required_qualifications_summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
end
end

context 'when the course enrichments are not loaded' do
let(:enrichment) { build(:course_enrichment, :published, required_qualifications: 'GCSE Computer Science') }
let(:course) { create(:course, enrichments: [enrichment]) }

it 'returns the expected value' do
course.reload
expect(course.enrichments.loaded?).to be_falsey
summary = described_class.new(course).extract
expect(summary).to eq 'GCSE Computer Science'
end
end

context 'when required_qualifications enrichment attribute is blank' do
it 'assembles a whole summary based on course attributes' do
course = create(:course, :primary)
Expand Down

0 comments on commit c542ae3

Please sign in to comment.