From 90c52188f3e6a4dd0d0301f691286252eacbb267 Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Wed, 30 Oct 2024 16:40:51 +0000 Subject: [PATCH] Add spec for Course#last_published_at --- spec/models/course_spec.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/spec/models/course_spec.rb b/spec/models/course_spec.rb index 37da7d5279..08747231c0 100644 --- a/spec/models/course_spec.rb +++ b/spec/models/course_spec.rb @@ -3157,6 +3157,37 @@ end end + describe '#last_published_at' do + context 'with an unpublished course' do + let(:course) { create(:course, study_mode: :part_time, enrichments: [create(:course_enrichment)]) } + + it 'returns nil' do + expect(course.last_published_at).to be_nil + end + end + + context 'with a twice published course' do + let(:course) do + create(:course, study_mode: :part_time, enrichments: [ + create(:course_enrichment, :published, last_published_timestamp_utc: '1/1/2024'), + create(:course_enrichment, :published, last_published_timestamp_utc: '1/1/2023') + ]) + end + + it 'selects the enrichment with the latest date' do + expect(course.last_published_at).to eq('1/1/2024') + end + + context 'when the enrichments are not loaded' do + it 'selects the enrichment with the latest date' do + course.reload + expect(course.enrichments.loaded?).to be_falsey + expect(course.last_published_at).to eq('1/1/2024') + end + end + end + end + describe 'funding_type and program_type' do context 'setting the funding to apprenticeship' do it 'sets the funding to apprenticeship and program_type to pg_teaching_apprenticeship' do