Skip to content

Commit

Permalink
Republish Worldwide Organisation on Corporate Information Pages changes
Browse files Browse the repository at this point in the history
Currently, Organisations are republished when a related Corporate Information
Pages changes, but Worldwide Organisations are not. Now that we publish
Worldwide Corporate Information Pages, we want to change this.

This is important because the Worldwide Organisation content item surfaces
information about related Corporate Information Pages on it's `details` rather
than it's `links` (though the links are present as well, they aren't used. This
is consistent with the Organisation content item).
  • Loading branch information
jkempster34 committed Jun 26, 2023
1 parent ce49e51 commit 58880af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/models/corporate_information_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CorporateInformationPage < Edition
include ::Attachable
include Searchable

after_commit :republish_organisation_to_publishing_api
after_commit :republish_owning_organisation_to_publishing_api
after_commit :republish_about_page_to_publishing_api, unless: :about_page?
after_save :reindex_organisation_in_search_index, if: :about_page?

Expand Down Expand Up @@ -31,8 +31,8 @@ def process_associations_before_save(new_edition)
scope :with_organisation_govuk_status, ->(status) { joins(:organisation).where(organisations: { govuk_status: status }) }
scope :accessible_documents_policy, -> { where(corporate_information_page_type_id: CorporateInformationPageType::AccessibleDocumentsPolicy.id) }

def republish_organisation_to_publishing_api
Whitehall::PublishingApi.republish_async(owning_organisation) if owning_organisation.is_a?(Organisation)
def republish_owning_organisation_to_publishing_api
Whitehall::PublishingApi.republish_async(owning_organisation) if owning_organisation.present?
end

def republish_about_page_to_publishing_api
Expand Down
26 changes: 26 additions & 0 deletions test/unit/models/corporate_information_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,30 @@ class CorporateInformationPageTest < ActiveSupport::TestCase
corporate_information_page = create(:corporate_information_page, organisation: nil, worldwide_organisation: nil)
assert_nil corporate_information_page.base_path
end

test "republishes owning organisation after commit when present" do
organisation = create(:organisation)
corporate_information_page = create(:corporate_information_page, organisation:, worldwide_organisation: nil)

Whitehall::PublishingApi.expects(:republish_async).with(organisation).once

corporate_information_page.update!(body: "new body")
end

test "republishes owning worldwide organisation after commit when present" do
worldwide_organisation = create(:worldwide_organisation)
corporate_information_page = create(:corporate_information_page, organisation: nil, worldwide_organisation:)

Whitehall::PublishingApi.expects(:republish_async).with(worldwide_organisation).once

corporate_information_page.update!(body: "new body")
end

test "does not republish owning organisation when absent" do
corporate_information_page = create(:corporate_information_page, organisation: nil, worldwide_organisation: nil)

Whitehall::PublishingApi.expects(:republish_async).never

corporate_information_page.update!(body: "new body")
end
end

0 comments on commit 58880af

Please sign in to comment.