Skip to content

Commit

Permalink
Merge pull request #8567 from alphagov/republish-prime-ministers-page…
Browse files Browse the repository at this point in the history
…-when-person-is-updated

Republish prime ministers page when person is updated
  • Loading branch information
davidgisbey authored Nov 29, 2023
2 parents 04aa07e + bbbdeca commit a8dbd56
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/admin/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def edit; end

def update
if @person.update(person_params)
if @person.current_or_previous_prime_minister?
@person.historical_account.republish_to_publishing_api_async if @person.historical_account.present?
PresentPageToPublishingApiWorker.perform_async("PublishingApi::HistoricalAccountsIndexPresenter")
end

redirect_to [:admin, @person], notice: %("#{@person.name}" saved.)
else
render :edit
Expand Down
45 changes: 45 additions & 0 deletions test/functional/admin/people_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,51 @@ class Admin::PeopleControllerTest < ActionController::TestCase
assert_equal "960x640_jpeg.jpg", person.reload.image.filename
end

test "PUT :update does not republish the past prime ministers page if the person has not been the prime minister" do
person = create(:person)

PresentPageToPublishingApi
.expects(:new)
.never

Sidekiq::Testing.inline! do
put :update, params: {
id: person.id,
person: attributes_for(:person),
}
end
end

test "PUT :update republishes the past prime ministers page & the persons historical account if the person is or has been the prime minister" do
login_as :gds_admin
historical_account = build(:historical_account)
person = create(:pm, historical_account:)

service = mock

PresentPageToPublishingApi
.expects(:new)
.once
.returns(service)

service
.expects(:publish)
.once
.with(PublishingApi::HistoricalAccountsIndexPresenter)

HistoricalAccount
.any_instance
.expects(:republish_to_publishing_api_async)
.once

Sidekiq::Testing.inline! do
put :update, params: {
id: person.id,
person: attributes_for(:person),
}
end
end

test "should be able to destroy a destroyable person" do
person = create(:person, forename: "Dave")
delete :destroy, params: { id: person.id }
Expand Down

0 comments on commit a8dbd56

Please sign in to comment.