Skip to content

Commit

Permalink
Rename about us pages bulk content type
Browse files Browse the repository at this point in the history
This is specific to published about us pages, per the definition of
`about_us` from `HasCorporateInformationPages`

A regular migration is used here to ensure that the data is updated
at the same time as the enum changing, and to allow the change to be
made automatically during the deployment process
  • Loading branch information
yndajas committed May 30, 2024
1 parent aa76d7a commit 86f7201
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 31 deletions.
12 changes: 6 additions & 6 deletions app/helpers/admin/republishing_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def bulk_content_type_metadata
confirmation_path: admin_bulk_republishing_all_confirm_path("all-documents-with-pre-publication-editions"),
republish_method: -> { BulkRepublisher.new.republish_all_documents_with_pre_publication_editions },
},
all_organisation_about_us_pages: {
id: "all-organisation-about-us-pages",
name: "all organisation 'About Us' pages",
republishing_path: admin_bulk_republishing_all_republish_path("all-organisation-about-us-pages"),
confirmation_path: admin_bulk_republishing_all_confirm_path("all-organisation-about-us-pages"),
republish_method: -> { BulkRepublisher.new.republish_all_organisation_about_us_pages },
all_published_organisation_about_us_pages: {
id: "all-published-organisation-about-us-pages",
name: "all published organisation 'About us' pages",
republishing_path: admin_bulk_republishing_all_republish_path("all-published-organisation-about-us-pages"),
confirmation_path: admin_bulk_republishing_all_confirm_path("all-published-organisation-about-us-pages"),
republish_method: -> { BulkRepublisher.new.republish_all_published_organisation_about_us_pages },
},
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/republishing_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RepublishingEvent < ApplicationRecord

enum :bulk_content_type, %i[
all_documents
all_organisation_about_us_pages
all_documents_with_pre_publication_editions
all_published_organisation_about_us_pages
]
end
2 changes: 1 addition & 1 deletion app/services/bulk_republisher.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class BulkRepublisher
def republish_all_organisation_about_us_pages
def republish_all_published_organisation_about_us_pages
document_ids = Organisation.all.map(&:about_us).compact.pluck(:document_id)

document_ids.each do |document_id|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class RenameAllOrganisationAboutUsPagesBulkContentType < ActiveRecord::Migration[7.1]
def up
RepublishingEvent
.where(bulk_content_type: :all_organisation_about_us_pages)
.update_all(
bulk_content_type: :all_published_organisation_about_us_pages,
action: "All published organisation 'About us' pages have been queued for republishing",
)
end

def down
RepublishingEvent
.where(bulk_content_type: :all_published_organisation_about_us_pages)
.update_all(
bulk_content_type: :all_organisation_about_us_pages,
action: "All published organisation 'About Us' pages have been queued for republishing",
)
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_05_29_103123) do
ActiveRecord::Schema[7.1].define(version: 2024_05_30_154757) do
create_table "assets", charset: "utf8mb3", force: :cascade do |t|
t.string "asset_manager_id", null: false
t.string "variant", null: false
Expand Down
8 changes: 4 additions & 4 deletions features/bulk-republishing-content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature: Bulk republishing content
When I request a bulk republishing of all documents with pre-publication editions
Then I can see that all documents with pre-publication editions have been queued for republishing

Scenario: Republish all Organisation "About us" pages
Given Organisation "About us" pages exist
When I request a bulk republishing of the Organisation "About us" pages
Then I can see the Organisation "About us" pages have been queued for republishing
Scenario: Republish all published Organisation "About us" pages
Given Published organisation "About us" pages exist
When I request a bulk republishing of all published organisation "About us" pages
Then I can see all published organisation "About us" pages have been queued for republishing
10 changes: 5 additions & 5 deletions features/step_definitions/bulk_republishing_content_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
expect(page).to have_selector(".gem-c-success-alert", text: "All documents with pre-publication editions have been queued for republishing")
end

Given(/^Organisation "About us" pages exist$/) do
Given(/^Published organisation "About us" pages exist$/) do
2.times { create(:about_corporate_information_page) }
end

When(/^I request a bulk republishing of the Organisation "About us" pages$/) do
When(/^I request a bulk republishing of all published organisation "About us" pages$/) do
visit admin_republishing_index_path
find("#all-organisation-about-us-pages").click
find("#all-published-organisation-about-us-pages").click
fill_in "What is the reason for republishing?", with: "It needs republishing"
click_button("Confirm republishing")
end

Then(/^I can see the Organisation "About us" pages have been queued for republishing$/) do
expect(page).to have_selector(".gem-c-success-alert", text: "All organisation 'About us' pages have been queued for republishing")
Then(/^I can see all published organisation "About us" pages have been queued for republishing$/) do
expect(page).to have_selector(".gem-c-success-alert", text: "All published organisation 'About us' pages have been queued for republishing")
end
18 changes: 9 additions & 9 deletions test/functional/admin/bulk_republishing_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Admin::BulkRepublishingControllerTest < ActionController::TestCase
should_be_an_admin_controller

test "GDS Admin users should be able to GET :confirm_all with a valid parameterless bulk content type" do
get :confirm_all, params: { bulk_content_type: "all-organisation-about-us-pages" }
get :confirm_all, params: { bulk_content_type: "all-published-organisation-about-us-pages" }
assert_response :ok
end

Expand All @@ -20,30 +20,30 @@ class Admin::BulkRepublishingControllerTest < ActionController::TestCase
test "Non-GDS Admin users should not be able to GET :confirm_all" do
login_as :writer

get :confirm_all, params: { bulk_content_type: "all-organisation-about-us-pages" }
get :confirm_all, params: { bulk_content_type: "all-published-organisation-about-us-pages" }
assert_response :forbidden
end

test "GDS Admin users should be able to POST :republish_all with a valid bulk content type and a reason, creating a RepublishingEvent for the current user" do
BulkRepublisher.any_instance.expects(:republish_all_organisation_about_us_pages).once
BulkRepublisher.any_instance.expects(:republish_all_published_organisation_about_us_pages).once

post :republish_all, params: { bulk_content_type: "all-organisation-about-us-pages", reason: "this needs republishing" }
post :republish_all, params: { bulk_content_type: "all-published-organisation-about-us-pages", reason: "this needs republishing" }

newly_created_event = RepublishingEvent.last
assert_equal newly_created_event.user, current_user
assert_equal newly_created_event.reason, "this needs republishing"
assert_equal newly_created_event.action, "All organisation 'About us' pages have been queued for republishing"
assert_equal newly_created_event.action, "All published organisation 'About us' pages have been queued for republishing"
assert_equal newly_created_event.bulk, true
assert_equal newly_created_event.bulk_content_type, "all_organisation_about_us_pages"
assert_equal newly_created_event.bulk_content_type, "all_published_organisation_about_us_pages"

assert_redirected_to admin_republishing_index_path
assert_equal "All organisation 'About us' pages have been queued for republishing", flash[:notice]
assert_equal "All published organisation 'About us' pages have been queued for republishing", flash[:notice]
end

test "GDS Admin users should encounter an error on POST :republish_all without a `reason` and be sent back to the confirm_all page" do
BulkRepublisher.expects(:new).never

post :republish_all, params: { bulk_content_type: "all-organisation-about-us-pages", reason: "" }
post :republish_all, params: { bulk_content_type: "all-published-organisation-about-us-pages", reason: "" }

assert_equal ["Reason can't be blank"], assigns(:republishing_event).errors.full_messages
assert_template "confirm_all"
Expand All @@ -61,7 +61,7 @@ class Admin::BulkRepublishingControllerTest < ActionController::TestCase

login_as :writer

post :republish_all, params: { bulk_content_type: "all-organisation-about-us-pages", reason: "this needs republishing" }
post :republish_all, params: { bulk_content_type: "all-published-organisation-about-us-pages", reason: "this needs republishing" }
assert_response :forbidden
end
end
2 changes: 1 addition & 1 deletion test/functional/admin/republishing_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Admin::RepublishingControllerTest < ActionController::TestCase

assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(1) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-documents/confirm']", text: "Republish all documents"
assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(2) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-documents-with-pre-publication-editions/confirm']", text: "Republish all documents with pre-publication editions"
assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(3) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-organisation-about-us-pages/confirm']", text: "Republish all organisation 'About Us' pages"
assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(3) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-published-organisation-about-us-pages/confirm']", text: "Republish all published organisation 'About us' pages"

assert_response :ok
end
Expand Down
17 changes: 14 additions & 3 deletions test/unit/app/services/bulk_republisher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class BulkRepublisherTest < ActiveSupport::TestCase
extend Minitest::Spec::DSL

describe "#republish_all_organisation_about_us_pages" do
test "queues Organisation 'About us' pages for republishing" do
describe "#republish_all_published_organisation_about_us_pages" do
test "queues all published organisation 'About us' pages for republishing" do
queue_sequence = sequence("queue")

2.times do
Expand All @@ -16,7 +16,18 @@ class BulkRepublisherTest < ActiveSupport::TestCase
.in_sequence(queue_sequence)
end

BulkRepublisher.new.republish_all_organisation_about_us_pages
BulkRepublisher.new.republish_all_published_organisation_about_us_pages
end

test "doesn't queue draft organisation 'About us' pages for republishing" do
about_us_page = create(:draft_about_corporate_information_page)

PublishingApiDocumentRepublishingWorker
.expects(:perform_async_in_queue)
.with("bulk_republishing", about_us_page.document_id, true)
.never

BulkRepublisher.new.republish_all_published_organisation_about_us_pages
end
end

Expand Down

0 comments on commit 86f7201

Please sign in to comment.