From 4ca649e556f2d5ce9427e7b5810f5de491bfcf4d Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Mon, 25 Nov 2024 11:16:46 +0000 Subject: [PATCH] Undiscard the course when publishing Courses may be #published? and still not appear in the API. When we publish a course, we should expect it to appear in the API. When publishing a course we should undiscard the course if it has been discarded --- app/services/courses/publish_service.rb | 1 + spec/services/courses/publish_service_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/app/services/courses/publish_service.rb b/app/services/courses/publish_service.rb index 5286a132d9..ccdec1b5f1 100644 --- a/app/services/courses/publish_service.rb +++ b/app/services/courses/publish_service.rb @@ -26,6 +26,7 @@ def call def publish_course Course.transaction do + course.undiscard course.publish_sites course.publish_enrichment(user) course.application_status_open! diff --git a/spec/services/courses/publish_service_spec.rb b/spec/services/courses/publish_service_spec.rb index b4dd8df767..9fe3b00a39 100644 --- a/spec/services/courses/publish_service_spec.rb +++ b/spec/services/courses/publish_service_spec.rb @@ -29,6 +29,17 @@ end end + describe 'when the course is discarded' do + let(:course) { create(:course, :publishable, uuid:, discarded_at: 1.minute.ago) } + + it 'the course is undiscarded and published' do + allow(Course).to receive(:find_by).with({ uuid: uuid }).and_return(course) + subject.call + expect(course.reload).to be_published + expect(course.reload).to be_undiscarded + end + end + describe 'publishing the course fails' do it 'the course is unpublished' do allow(Course).to receive(:find_by).with({ uuid: uuid }).and_return(course)