From 707f2bf0c168462bb21035baf229a2d0d9f0e108 Mon Sep 17 00:00:00 2001 From: ChrisBAshton Date: Fri, 21 Jun 2024 08:48:24 +0100 Subject: [PATCH] Remove unused `save_draft` method This was a nice idea in principle, but the only use case we had for it was for creating a preview version of the ministers page after publishing a maintenance message on the live stack. The nature of using workers for this meant that they could run out of order and we'd end up overriding the maintenance message on live. We've now changed how we apply the live and draft payloads, and this method is no longer called. Rather than keep it 'just in case' something in the future wants it, we'll delete it and this commit can be reverted in future if a need for it arises. --- app/models/concerns/reshuffle_mode.rb | 10 +++++----- .../present_page_to_publishing_api_worker.rb | 8 ++------ lib/present_page_to_publishing_api.rb | 6 ------ test/unit/app/models/reshuffle_mode_test.rb | 6 +++--- ...resent_page_to_publishing_api_worker_test.rb | 9 --------- .../lib/present_page_to_publishing_api_test.rb | 17 ----------------- 6 files changed, 10 insertions(+), 46 deletions(-) diff --git a/app/models/concerns/reshuffle_mode.rb b/app/models/concerns/reshuffle_mode.rb index 227d6f10acb..262adef44e1 100644 --- a/app/models/concerns/reshuffle_mode.rb +++ b/app/models/concerns/reshuffle_mode.rb @@ -7,15 +7,15 @@ def patch_links_ministers_index_page_to_publishing_api end def republish_how_government_works_page_to_publishing_api - PresentPageToPublishingApiWorker.perform_async("PublishingApi::HowGovernmentWorksPresenter", update_live?) + if reshuffle_in_progress? + PresentPageToPublishingApiWorker.perform_async("PublishingApi::HowGovernmentWorksEnableReshufflePresenter") + else + PresentPageToPublishingApiWorker.perform_async("PublishingApi::HowGovernmentWorksPresenter") + end end def reshuffle_in_progress? SitewideSetting.find_by(key: :minister_reshuffle_mode)&.on || false end end - - def update_live? - !reshuffle_in_progress? - end end diff --git a/app/workers/present_page_to_publishing_api_worker.rb b/app/workers/present_page_to_publishing_api_worker.rb index b08e14ff4ca..c1954bab1b6 100644 --- a/app/workers/present_page_to_publishing_api_worker.rb +++ b/app/workers/present_page_to_publishing_api_worker.rb @@ -1,9 +1,5 @@ class PresentPageToPublishingApiWorker < WorkerBase - def perform(presenter, update_live = true) - if update_live - PresentPageToPublishingApi.new.publish(presenter.constantize) - else - PresentPageToPublishingApi.new.save_draft(presenter.constantize) - end + def perform(presenter) + PresentPageToPublishingApi.new.publish(presenter.constantize) end end diff --git a/lib/present_page_to_publishing_api.rb b/lib/present_page_to_publishing_api.rb index c5ce13272a4..7806b288f27 100644 --- a/lib/present_page_to_publishing_api.rb +++ b/lib/present_page_to_publishing_api.rb @@ -10,10 +10,4 @@ def patch_links(presenter_class) payload = presenter_class.new Services.publishing_api.patch_links(payload.content_id, links: payload.links) end - - def save_draft(presenter_class) - payload = presenter_class.new - Services.publishing_api.put_content(payload.content_id, payload.content) - Services.publishing_api.patch_links(payload.content_id, links: payload.links) - end end diff --git a/test/unit/app/models/reshuffle_mode_test.rb b/test/unit/app/models/reshuffle_mode_test.rb index ef80f2939f5..f524d585bbd 100644 --- a/test/unit/app/models/reshuffle_mode_test.rb +++ b/test/unit/app/models/reshuffle_mode_test.rb @@ -30,13 +30,13 @@ class ClassThatIncludesReshuffleMode < ApplicationRecord describe "#republish_how_government_works_page_to_publishing_api" do it "republishes the 'How Government Works' page" do - PresentPageToPublishingApiWorker.expects(:perform_async).with("PublishingApi::HowGovernmentWorksPresenter", true).once + PresentPageToPublishingApiWorker.expects(:perform_async).with("PublishingApi::HowGovernmentWorksPresenter").once ClassThatIncludesReshuffleMode.new.republish_how_government_works_page_to_publishing_api end - it "only saves to the draft stack when reshuffle mode is switched on" do - PresentPageToPublishingApiWorker.expects(:perform_async).with("PublishingApi::HowGovernmentWorksPresenter", false).once + it "publishes the 'reshuffle presenter' version when reshuffle mode is on" do + PresentPageToPublishingApiWorker.expects(:perform_async).with("PublishingApi::HowGovernmentWorksEnableReshufflePresenter").once reshuffle_mode = ClassThatIncludesReshuffleMode.new reshuffle_mode.stubs(:reshuffle_in_progress?).returns(true) diff --git a/test/unit/app/workers/present_page_to_publishing_api_worker_test.rb b/test/unit/app/workers/present_page_to_publishing_api_worker_test.rb index aa2690e27e0..e4adb2f511b 100644 --- a/test/unit/app/workers/present_page_to_publishing_api_worker_test.rb +++ b/test/unit/app/workers/present_page_to_publishing_api_worker_test.rb @@ -9,13 +9,4 @@ class PresentPageToPublishingApiWorkerTest < ActiveSupport::TestCase PresentPageToPublishingApiWorker.new.perform("PublishingApi::HowGovernmentWorksPresenter") end - - test "calls `save_draft` method when `update_live` parameter is false" do - service = mock - PresentPageToPublishingApi.expects(:new).returns(service) - - service.expects(:save_draft).with(PublishingApi::HowGovernmentWorksPresenter) - - PresentPageToPublishingApiWorker.new.perform("PublishingApi::HowGovernmentWorksPresenter", false) - end end diff --git a/test/unit/lib/present_page_to_publishing_api_test.rb b/test/unit/lib/present_page_to_publishing_api_test.rb index 8eaa9d4e332..05f56f477e3 100644 --- a/test/unit/lib/present_page_to_publishing_api_test.rb +++ b/test/unit/lib/present_page_to_publishing_api_test.rb @@ -37,12 +37,6 @@ class PresentPageToPublishingApiTest < ActiveSupport::TestCase end end - describe "#save_draft" do - it "saves the operation index page to publishing api draft stack" do - assert_content_is_presented_to_publishing_api_draft_stack(PublishingApi::OperationalFieldsIndexPresenter) - end - end - def assert_content_is_presented_to_publishing_api(presenter_class, locale: "en") presenter = presenter_class.new expected_content = presenter.content @@ -53,15 +47,4 @@ def assert_content_is_presented_to_publishing_api(presenter_class, locale: "en") PresentPageToPublishingApi.new.publish(presenter_class) end - - def assert_content_is_presented_to_publishing_api_draft_stack(presenter_class, locale: "en") - presenter = presenter_class.new - expected_content = presenter.content - - Services.publishing_api.expects(:put_content).with(presenter.content_id, expected_content).once - Services.publishing_api.expects(:patch_links).with(presenter.content_id, links: presenter.links).once - Services.publishing_api.expects(:publish).with(presenter.content_id, nil, locale:).never - - PresentPageToPublishingApi.new.save_draft(presenter_class) - end end