Skip to content

Commit

Permalink
Remove unused save_draft method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ChrisBAshton committed Jun 21, 2024
1 parent a578dcd commit 707f2bf
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 46 deletions.
10 changes: 5 additions & 5 deletions app/models/concerns/reshuffle_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 2 additions & 6 deletions app/workers/present_page_to_publishing_api_worker.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions lib/present_page_to_publishing_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions test/unit/app/models/reshuffle_mode_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 0 additions & 17 deletions test/unit/lib/present_page_to_publishing_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 707f2bf

Please sign in to comment.