diff --git a/db/migrate/20250121102923_add_internal_change_note_to_content_block_editions.rb b/db/migrate/20250121102923_add_internal_change_note_to_content_block_editions.rb
new file mode 100644
index 00000000000..a43271345cd
--- /dev/null
+++ b/db/migrate/20250121102923_add_internal_change_note_to_content_block_editions.rb
@@ -0,0 +1,5 @@
+class AddInternalChangeNoteToContentBlockEditions < ActiveRecord::Migration[7.1]
+ def change
+ add_column :content_block_editions, :internal_change_note, :string
+ end
+end
diff --git a/db/migrate/20250122155447_add_change_note_and_major_change_to_content_block_editions.rb b/db/migrate/20250122155447_add_change_note_and_major_change_to_content_block_editions.rb
new file mode 100644
index 00000000000..bbf6c97c7f5
--- /dev/null
+++ b/db/migrate/20250122155447_add_change_note_and_major_change_to_content_block_editions.rb
@@ -0,0 +1,15 @@
+class AddChangeNoteAndMajorChangeToContentBlockEditions < ActiveRecord::Migration[7.1]
+ def up
+ change_table :content_block_editions, bulk: true do |t|
+ t.string "change_note"
+ t.boolean "major_change"
+ end
+ end
+
+ def down
+ change_table :content_block_editions, bulk: true do |t|
+ t.remove "change_note"
+ t.remove "major_change"
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 5fcfcf55d69..44dfb96df21 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.1].define(version: 2025_01_08_102234) do
+ActiveRecord::Schema[7.1].define(version: 2025_01_22_155447) do
create_table "assets", charset: "utf8mb3", force: :cascade do |t|
t.string "asset_manager_id", null: false
t.string "variant", null: false
@@ -233,6 +233,9 @@
t.datetime "scheduled_publication", precision: nil
t.text "instructions_to_publishers"
t.string "title", default: "", null: false
+ t.string "internal_change_note"
+ t.string "change_note"
+ t.boolean "major_change"
t.index ["document_id"], name: "index_content_block_editions_on_document_id"
t.index ["user_id"], name: "index_content_block_editions_on_user_id"
end
diff --git a/lib/engines/content_block_manager/app/components/content_block_manager/content_block_edition/show/confirm_summary_list_component.rb b/lib/engines/content_block_manager/app/components/content_block_manager/content_block_edition/show/confirm_summary_list_component.rb
index b9810a90162..dca3375e38d 100644
--- a/lib/engines/content_block_manager/app/components/content_block_manager/content_block_edition/show/confirm_summary_list_component.rb
+++ b/lib/engines/content_block_manager/app/components/content_block_manager/content_block_edition/show/confirm_summary_list_component.rb
@@ -57,7 +57,7 @@ def instructions_item
def edit_action
{
- href: helpers.content_block_manager.content_block_manager_content_block_workflow_path(id: content_block_edition.id, step: ContentBlockManager::ContentBlock::Editions::WorkflowController::NEW_BLOCK_STEPS[:edit_draft]),
+ href: helpers.content_block_manager.content_block_manager_content_block_workflow_path(id: content_block_edition.id, step: :edit_draft),
link_text: "Edit",
}
end
diff --git a/lib/engines/content_block_manager/app/controllers/concerns/can_schedule_or_publish.rb b/lib/engines/content_block_manager/app/controllers/concerns/can_schedule_or_publish.rb
index 215e25c3872..4ba0753cdc9 100644
--- a/lib/engines/content_block_manager/app/controllers/concerns/can_schedule_or_publish.rb
+++ b/lib/engines/content_block_manager/app/controllers/concerns/can_schedule_or_publish.rb
@@ -77,7 +77,7 @@ def scheduled_publication_date_params
def review_update_url
content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
- step: ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:review_update],
+ step: :review,
)
end
diff --git a/lib/engines/content_block_manager/app/controllers/concerns/workflow/show_methods.rb b/lib/engines/content_block_manager/app/controllers/concerns/workflow/show_methods.rb
new file mode 100644
index 00000000000..015dab89f52
--- /dev/null
+++ b/lib/engines/content_block_manager/app/controllers/concerns/workflow/show_methods.rb
@@ -0,0 +1,93 @@
+module Workflow::ShowMethods
+ extend ActiveSupport::Concern
+
+ SHOW_ACTIONS = {
+ edit_draft: :edit_draft,
+ review_links: :review_links,
+ schedule_publishing: :schedule_publishing,
+ internal_note: :internal_note,
+ change_note: :change_note,
+ review: :review,
+ review_update: :review_update,
+ confirmation: :confirmation,
+ }.freeze
+
+ def edit_draft
+ @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
+ @form = ContentBlockManager::ContentBlock::EditionForm.for(
+ content_block_edition: @content_block_edition,
+ schema: @schema,
+ )
+
+ render "content_block_manager/content_block/editions/new"
+ end
+
+ def review_links
+ @content_block_document = @content_block_edition.document
+ @order = params[:order]
+ @page = params[:page]
+
+ @host_content_items = ContentBlockManager::HostContentItem.for_document(
+ @content_block_document,
+ order: @order,
+ page: @page,
+ )
+
+ render :review_links
+ end
+
+ def schedule_publishing
+ @content_block_document = @content_block_edition.document
+
+ render :schedule_publishing
+ end
+
+ def internal_note
+ @content_block_document = @content_block_edition.document
+ @back_path = content_block_manager.content_block_manager_content_block_workflow_path(
+ @content_block_edition,
+ step: :schedule_publishing,
+ )
+
+ render :internal_note
+ end
+
+ def change_note
+ @content_block_document = @content_block_edition.document
+ @back_path = content_block_manager.content_block_manager_content_block_workflow_path(
+ @content_block_edition,
+ step: :internal_note,
+ )
+
+ render :change_note
+ end
+
+ def review_update
+ @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
+
+ @url = review_update_url
+ @back_path = content_block_manager.content_block_manager_content_block_workflow_path(
+ @content_block_edition,
+ step: :change_note,
+ )
+
+ render :review
+ end
+
+ def review
+ @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
+ @back_path = content_block_manager.content_block_manager_content_block_documents_path
+
+ @url = review_url
+
+ render :review
+ end
+
+ def confirmation
+ @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
+
+ @confirmation_copy = ContentBlockManager::ConfirmationCopyPresenter.new(@content_block_edition)
+
+ render :confirmation
+ end
+end
diff --git a/lib/engines/content_block_manager/app/controllers/concerns/workflow/update_methods.rb b/lib/engines/content_block_manager/app/controllers/concerns/workflow/update_methods.rb
new file mode 100644
index 00000000000..f1bf0af07de
--- /dev/null
+++ b/lib/engines/content_block_manager/app/controllers/concerns/workflow/update_methods.rb
@@ -0,0 +1,76 @@
+module Workflow::UpdateMethods
+ extend ActiveSupport::Concern
+
+ REVIEW_ERROR = Data.define(:attribute, :full_message)
+
+ UPDATE_ACTIONS = {
+ review_links: :redirect_to_schedule,
+ schedule_publishing: :validate_schedule,
+ internal_note: :update_internal_note,
+ change_note: :update_change_note,
+ review_update: :validate_review_page,
+ review: :validate_review_page,
+ }.freeze
+
+ def redirect_to_schedule
+ redirect_to content_block_manager.content_block_manager_content_block_workflow_path(
+ id: @content_block_edition.id,
+ step: :schedule_publishing,
+ )
+ end
+
+ def validate_schedule
+ @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
+
+ validate_scheduled_edition
+
+ redirect_to content_block_manager.content_block_manager_content_block_workflow_path(
+ id: @content_block_edition.id,
+ step: :internal_note,
+ )
+ rescue ActiveRecord::RecordInvalid
+ render "content_block_manager/content_block/editions/workflow/schedule_publishing"
+ end
+
+ def update_internal_note
+ @content_block_edition.update!(internal_change_note: edition_params[:internal_change_note])
+
+ redirect_to content_block_manager.content_block_manager_content_block_workflow_path(
+ id: @content_block_edition.id,
+ step: :change_note,
+ )
+ end
+
+ def update_change_note
+ @content_block_edition.assign_attributes(change_note: edition_params[:change_note], major_change: edition_params[:major_change])
+ @content_block_edition.save!(context: :change_note)
+
+ redirect_to content_block_manager.content_block_manager_content_block_workflow_path(
+ id: @content_block_edition.id,
+ step: :review_update,
+ )
+ rescue ActiveRecord::RecordInvalid
+ render :change_note
+ end
+
+ def validate_review_page
+ if params[:is_confirmed].blank?
+ @confirm_error_copy = I18n.t("content_block_edition.review_page.errors.confirm")
+ @error_summary_errors = [{ text: @confirm_error_copy, href: "#is_confirmed-0" }]
+ @url = on_review_page? ? review_url : review_update_url
+ render "content_block_manager/content_block/editions/workflow/review"
+ else
+ schedule_or_publish
+ end
+ end
+
+private
+
+ def on_review_page?
+ params[:step] == :review
+ end
+
+ def on_review_update_page?
+ params[:step] == :review_update
+ end
+end
diff --git a/lib/engines/content_block_manager/app/controllers/content_block_manager/base_controller.rb b/lib/engines/content_block_manager/app/controllers/content_block_manager/base_controller.rb
index 5096b704daf..248859b8de6 100644
--- a/lib/engines/content_block_manager/app/controllers/content_block_manager/base_controller.rb
+++ b/lib/engines/content_block_manager/app/controllers/content_block_manager/base_controller.rb
@@ -26,6 +26,9 @@ def edition_params
"scheduled_publication(4i)",
"scheduled_publication(5i)",
:title,
+ :internal_change_note,
+ :change_note,
+ :major_change,
document_attributes: %w[block_type],
details: @schema.permitted_params,
)
diff --git a/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/documents/schedule_controller.rb b/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/documents/schedule_controller.rb
index c5b2d929089..25fb87741df 100644
--- a/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/documents/schedule_controller.rb
+++ b/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/documents/schedule_controller.rb
@@ -16,7 +16,7 @@ def update
validate_scheduled_edition
- redirect_to content_block_manager.content_block_manager_content_block_workflow_path(@content_block_edition, step: :review_update)
+ redirect_to content_block_manager.content_block_manager_content_block_workflow_path(@content_block_edition, step: :review)
rescue ActiveRecord::RecordInvalid
render "content_block_manager/content_block/documents/schedule/edit"
end
diff --git a/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/editions/workflow_controller.rb b/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/editions/workflow_controller.rb
index 330c17eb890..36379c98bfc 100644
--- a/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/editions/workflow_controller.rb
+++ b/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/editions/workflow_controller.rb
@@ -1,56 +1,31 @@
class ContentBlockManager::ContentBlock::Editions::WorkflowController < ContentBlockManager::BaseController
include CanScheduleOrPublish
-
- NEW_BLOCK_STEPS = {
- review: "review",
- edit_draft: "edit_draft",
- }.freeze
-
- UPDATE_BLOCK_STEPS = {
- review_links: "review_links",
- schedule_publishing: "schedule_publishing",
- review_update: "review_update",
- }.freeze
-
- SHARED_STEPS = {
- confirmation: "confirmation",
- }.freeze
+ include Workflow::ShowMethods
+ include Workflow::UpdateMethods
def show
- step = params[:step]
- @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
- @schema = ContentBlockManager::ContentBlock::Schema.find_by_block_type(@content_block_edition.document.block_type)
+ step = params[:step].to_sym
+ action = SHOW_ACTIONS[step]
- case step
- when NEW_BLOCK_STEPS[:edit_draft]
- edit_draft
- when UPDATE_BLOCK_STEPS[:review_links]
- review_links
- when UPDATE_BLOCK_STEPS[:schedule_publishing]
- schedule_publishing
- when NEW_BLOCK_STEPS[:review]
- review
- when UPDATE_BLOCK_STEPS[:review_update]
- review_update
- when SHARED_STEPS[:confirmation]
- confirmation
+ if action
+ @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
+ @schema = ContentBlockManager::ContentBlock::Schema.find_by_block_type(@content_block_edition.document.block_type)
+ send(action)
+ else
+ raise ActionController::RoutingError, "Step #{step} does not exist"
end
end
def update
- step = params[:step]
- @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
- @schema = ContentBlockManager::ContentBlock::Schema.find_by_block_type(@content_block_edition.document.block_type)
+ step = params[:step].to_sym
+ action = UPDATE_ACTIONS[step]
- case step
- when UPDATE_BLOCK_STEPS[:review_links]
- redirect_to content_block_manager.content_block_manager_content_block_workflow_path(id: @content_block_edition.id, step: :schedule_publishing)
- when UPDATE_BLOCK_STEPS[:schedule_publishing]
- validate_schedule
- when UPDATE_BLOCK_STEPS[:review_update]
- validate_review_page("review_update")
- when NEW_BLOCK_STEPS[:review]
- validate_review_page("review")
+ if action
+ @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
+ @schema = ContentBlockManager::ContentBlock::Schema.find_by_block_type(@content_block_edition.document.block_type)
+ send(action)
+ else
+ raise ActionController::RoutingError, "Step #{step} does not exist"
end
end
@@ -61,89 +36,10 @@ def context
private
- def edit_draft
- @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
- @form = ContentBlockManager::ContentBlock::EditionForm.for(
- content_block_edition: @content_block_edition,
- schema: @schema,
- )
-
- render "content_block_manager/content_block/editions/new"
- end
-
- def review
- @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
-
- @url = review_url
-
- render :review
- end
-
def review_url
content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
- step: ContentBlockManager::ContentBlock::Editions::WorkflowController::NEW_BLOCK_STEPS[:review],
- )
- end
-
- def validate_schedule
- @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
-
- validate_scheduled_edition
-
- redirect_to content_block_manager.content_block_manager_content_block_workflow_path(@content_block_edition, step: :review_update)
- rescue ActiveRecord::RecordInvalid
- render "content_block_manager/content_block/editions/workflow/schedule_publishing"
- end
-
- def review_update
- @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
-
- @url = review_update_url
-
- render :review
- rescue ActiveRecord::RecordInvalid
- render :schedule_publishing
- end
-
- def confirmation
- @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
-
- @confirmation_copy = ContentBlockManager::ConfirmationCopyPresenter.new(@content_block_edition)
-
- render :confirmation
- end
-
- def review_links
- @content_block_document = @content_block_edition.document
- @order = params[:order]
- @page = params[:page]
-
- @host_content_items = ContentBlockManager::HostContentItem.for_document(
- @content_block_document,
- order: @order,
- page: @page,
+ step: :review,
)
-
- render :review_links
- end
-
- def schedule_publishing
- @content_block_document = @content_block_edition.document
-
- render :schedule_publishing
- end
-
- REVIEW_ERROR = Data.define(:attribute, :full_message)
-
- def validate_review_page(step)
- if (step == NEW_BLOCK_STEPS[:review] || step == UPDATE_BLOCK_STEPS[:review_update]) && params[:is_confirmed].blank?
- @confirm_error_copy = I18n.t("content_block_edition.review_page.errors.confirm")
- @error_summary_errors = [{ text: @confirm_error_copy, href: "#is_confirmed-0" }]
- @url = step == NEW_BLOCK_STEPS[:review] ? review_url : review_update_url
- render "content_block_manager/content_block/editions/workflow/review"
- else
- schedule_or_publish
- end
end
end
diff --git a/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/editions_controller.rb b/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/editions_controller.rb
index 70b88058c1f..ed5248ab4e2 100644
--- a/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/editions_controller.rb
+++ b/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/editions_controller.rb
@@ -19,7 +19,7 @@ def new
def create
@schema = ContentBlockManager::ContentBlock::Schema.find_by_block_type(block_type_param)
new_edition = ContentBlockManager::CreateEditionService.new(@schema).call(edition_params, document_id: params[:document_id])
- step = params[:document_id] ? ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:review_links] : ContentBlockManager::ContentBlock::Editions::WorkflowController::NEW_BLOCK_STEPS[:review]
+ step = params[:document_id] ? :review_links : :review
redirect_to content_block_manager.content_block_manager_content_block_workflow_path(id: new_edition.id, step:)
rescue ActiveRecord::RecordInvalid => e
@form = ContentBlockManager::ContentBlock::EditionForm.for(content_block_edition: e.record, schema: @schema)
diff --git a/lib/engines/content_block_manager/app/models/content_block_manager/content_block/edition.rb b/lib/engines/content_block_manager/app/models/content_block_manager/content_block/edition.rb
index 1093dca6531..ba4cd9b738e 100644
--- a/lib/engines/content_block_manager/app/models/content_block_manager/content_block/edition.rb
+++ b/lib/engines/content_block_manager/app/models/content_block_manager/content_block/edition.rb
@@ -2,6 +2,8 @@ module ContentBlockManager
module ContentBlock
class Edition < ApplicationRecord
validates :title, presence: true
+ validates :change_note, presence: true, if: :major_change?, on: :change_note
+ validates :major_change, inclusion: [true, false], on: :change_note
include Documentable
include HasAuditTrail
diff --git a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/change_note.html.erb b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/change_note.html.erb
new file mode 100644
index 00000000000..ed6c8389a72
--- /dev/null
+++ b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/change_note.html.erb
@@ -0,0 +1,67 @@
+<% content_for :context, context %>
+<% content_for :title, "Do users have to know the content has changed?" %>
+<% content_for :title_margin_bottom, 4 %>
+<% content_for :back_link do %>
+ <%= render "govuk_publishing_components/components/back_link", {
+ href: @back_path,
+ } %>
+<% end %>
+
+<% content_for :error_summary, render(Admin::ErrorSummaryComponent.new(object: @content_block_edition)) %>
+
+
+
+ <%= form_with url: content_block_manager.content_block_manager_content_block_workflow_path(
+ @content_block_edition,
+ step: :change_note,
+ ), method: :put do %>
+
+ <%= render "govuk_publishing_components/components/radio", {
+ name: "content_block/edition[major_change]",
+ id: "content_block_manager_content_block_edition_major_change",
+ error_items: errors_for(@content_block_edition.errors, :major_change),
+ items: [
+ {
+ value: "1",
+ checked: @content_block_edition.major_change === true,
+ text: "Yes - information has been added, updated or removed",
+ hint_text: "A change note will be published on the page and emailed to users subscribed to email alerts. The 'last updated' date will change.",
+ bold: true,
+ conditional: render("govuk_publishing_components/components/textarea", {
+ label: {
+ text: "Describe the edit for users",
+ },
+ name: "content_block/edition[change_note]",
+ id: "content_block_manager_content_block_edition_change_note",
+ error_items: errors_for(@content_block_edition.errors, :change_note),
+ value: @content_block_edition.change_note,
+ hint: (tag.p('Tell users what has changed, where and why. Write in full sentences, leading with the most important words. For example, "College A has been removed from the registered sponsors list because its licence has been suspended."', class: "govuk-!-margin-bottom-0 govuk-!-margin-top-0") +
+ link_to("Guidance about change notes (opens in a new tab)", "https://www.gov.uk/guidance/content-design/writing-for-gov-uk#change-notes", target: "_blank", class: "govuk-link", rel: "noopener")).html_safe,
+ }),
+ },
+ {
+ value: "0",
+ checked: @content_block_edition.major_change === false,
+ text: "No - it's a minor edit that does not change the meaning",
+ hint_text: "This includes fixing a typo or broken link, a style change or similar. Users signed up to email alerts will not get notified and the 'last updated' date will not change.",
+ bold: true,
+ },
+ ],
+ } %>
+
+
+ <%= render "govuk_publishing_components/components/button", {
+ text: "Save and continue",
+ name: "save_and_continue",
+ value: "Save and continue",
+ type: "submit",
+ } %>
+ <%= render "govuk_publishing_components/components/button", {
+ text: "Cancel",
+ href: @back_path,
+ secondary_solid: true,
+ } %>
+
+ <% end %>
+
+
diff --git a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/internal_note.html.erb b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/internal_note.html.erb
new file mode 100644
index 00000000000..0c6617b024f
--- /dev/null
+++ b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/internal_note.html.erb
@@ -0,0 +1,40 @@
+<% content_for :context, context %>
+<% content_for :title, "Add internal change note" %>
+<% content_for :title_margin_bottom, 4 %>
+<% content_for :back_link do %>
+ <%= render "govuk_publishing_components/components/back_link", {
+ href: @back_path,
+ } %>
+<% end %>
+
+
+
+ <%= form_with url: content_block_manager.content_block_manager_content_block_workflow_path(
+ @content_block_edition,
+ step: :internal_note,
+ ), method: :put do %>
+ <%= render "govuk_publishing_components/components/textarea", {
+ label: {
+ text: "Describe the change for internal users",
+ },
+ name: "content_block/edition[internal_change_note]",
+ id: "content_block_manager_content_block_edition_title",
+ value: @content_block_edition.internal_change_note,
+ } %>
+
+
+ <%= render "govuk_publishing_components/components/button", {
+ text: "Save and continue",
+ name: "save_and_continue",
+ value: "Save and continue",
+ type: "submit",
+ } %>
+ <%= render "govuk_publishing_components/components/button", {
+ text: "Cancel",
+ href: @back_path,
+ secondary_solid: true,
+ } %>
+
+ <% end %>
+
+
diff --git a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/review.html.erb b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/review.html.erb
index 29877f4de0f..a942083daed 100644
--- a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/review.html.erb
+++ b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/review.html.erb
@@ -2,7 +2,7 @@
<% content_for :title, "Review #{@content_block_edition.block_type.humanize.downcase}" %>
<% content_for :back_link do %>
<%= render "govuk_publishing_components/components/back_link", {
- href: content_block_manager.content_block_manager_content_block_documents_path,
+ href: @back_path,
} %>
<% end %>
diff --git a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/review_links.html.erb b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/review_links.html.erb
index 8d7e730e5bd..3dd750679e9 100644
--- a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/review_links.html.erb
+++ b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/review_links.html.erb
@@ -42,7 +42,7 @@
<%= form_with(
url: content_block_manager.content_block_manager_content_block_workflow_path(
edition_id: @content_block_edition.id,
- step: ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:review_links],
+ step: :review_links,
),
method: :put,
) do %>
diff --git a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/schedule_publishing.html.erb b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/schedule_publishing.html.erb
index 09c0fe3f9c7..6de6c274c63 100644
--- a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/schedule_publishing.html.erb
+++ b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/schedule_publishing.html.erb
@@ -5,11 +5,11 @@
context:,
back_link: content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
- step: ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:review_links],
+ step: :review_links,
),
form_url: content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
- step: ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:schedule_publishing],
+ step: :schedule_publishing,
),
is_rescheduling: false,
)
diff --git a/lib/engines/content_block_manager/config/locales/en.yml b/lib/engines/content_block_manager/config/locales/en.yml
index 8cefe290ccf..2dcb6f2ae82 100644
--- a/lib/engines/content_block_manager/config/locales/en.yml
+++ b/lib/engines/content_block_manager/config/locales/en.yml
@@ -13,6 +13,8 @@ en:
attributes:
schedule_publishing:
blank: "Select publish date"
+ major_change:
+ inclusion: "Select if users have to know the content has changed"
scheduled_publication:
blank: "Scheduled publication date and time cannot be blank"
invalid_date: "Invalid scheduled publication date and time"
diff --git a/lib/engines/content_block_manager/features/edit_object.feature b/lib/engines/content_block_manager/features/edit_object.feature
index 4782a0cf91d..ad9e0ff7375 100644
--- a/lib/engines/content_block_manager/features/edit_object.feature
+++ b/lib/engines/content_block_manager/features/edit_object.feature
@@ -10,21 +10,25 @@ Feature: Edit a content object
Scenario: GDS Editor edits a content object
When I visit the Content Block Manager home page
- Then I should see the details for all documents
- When I click to view the document
- Then I should see the details for the email address content block
- When I click the first edit link
- Then I should see the edit form
+ And I click to view the document
+ And I click the first edit link
+ Then I should be on the "edit" step
And I should see a back link to the document page
When I fill out the form
- Then I am shown where the changes will take place
- And I see the rollup data for the dependent content
- And I should see a back link to the edit page
- When I save and continue
- Then I am asked when I want to publish the change
- And I should see a back link to the review page
+ Then I should be on the "review_links" step
+ And I should see a back link to the "edit" step
+ When I continue after reviewing the links
+ Then I should be on the "schedule_publishing" step
+ And I should see a back link to the "review_links" step
When I choose to publish the change now
- And I save and continue
+ Then I should be on the "internal_note" step
+ And I should see a back link to the "schedule_publishing" step
+ When I add an internal note
+ Then I should be on the "change_note" step
+ And I should see a back link to the "internal_note" step
+ When I add a change note
+ Then I should be on the "review" step
+ And I should see a back link to the "change_note" step
When I review and confirm my answers are correct
Then I should be taken to the confirmation page for a published block
When I click to view the content block
@@ -36,37 +40,31 @@ Feature: Edit a content object
When I visit the Content Block Manager home page
When I click to view the document
When I click the first edit link
- Then I should see the edit form
When I fill out the form
- Then I am shown where the changes will take place
- And I see the rollup data for the dependent content
And I click cancel
Then I should be taken back to the document page
And no draft Content Block Edition has been created
Scenario: GDS editor cancels the creation of an object before scheduling
When I visit the Content Block Manager home page
- When I click to view the document
+ And I click to view the document
When I click the first edit link
- Then I should see the edit form
- When I fill out the form
- Then I am shown where the changes will take place
- And I see the rollup data for the dependent content
- When I save and continue
- Then I am asked when I want to publish the change
- And I click cancel
+ And I fill out the form
+ And I continue after reviewing the links
+ When I click cancel
Then I should be taken back to the document page
And no draft Content Block Edition has been created
Scenario: GDS editor cancels the creation of an object before confirming answers
When I visit the Content Block Manager home page
- When I click to view the document
+ And I click to view the document
When I click the first edit link
- When I fill out the form
- When I save and continue
+ And I fill out the form
+ And I continue after reviewing the links
When I choose to publish the change now
- And I save and continue
- And I click cancel
+ And I add an internal note
+ And I add a change note
+ When I click cancel
Then I am taken back to Content Block Manager home page
And no draft Content Block Edition has been created
@@ -99,10 +97,10 @@ Feature: Edit a content object
When I click to view the document
When I click the first edit link
When I fill out the form
- Then I am shown where the changes will take place
- When I save and continue
+ And I continue after reviewing the links
And I choose to publish the change now
- When I save and continue
+ And I add an internal note
+ And I add a change note
Then I am asked to review my answers
When I click publish without confirming my details
Then I should see a message that I need to confirm the details are correct
@@ -110,14 +108,16 @@ Feature: Edit a content object
@enable-sidekiq-test-mode
Scenario: GDS editor can override a previously scheduled object
When I am updating a content block
- And I am asked when I want to publish the change
And I schedule the change for 7 days in the future
+ And I add an internal note
+ And I add a change note
When I review and confirm my answers are correct
When I revisit the edit page
Then I should see a warning telling me there is a scheduled change
When I make the changes
And I choose to publish the change now
- And I save and continue
+ And I add an internal note
+ And I add a change note
When I review and confirm my answers are correct
Then I should be taken to the confirmation page for a published block
When I click to view the content block
@@ -132,8 +132,6 @@ Feature: Edit a content object
Scenario: GDS editor can preview a host document
When I revisit the edit page
And I save and continue
- Then I am shown where the changes will take place
- And I see the rollup data for the dependent content
When I click on the first host document
Then the preview page opens in a new tab
When I click on a link within the frame
diff --git a/lib/engines/content_block_manager/features/reschedule_object.feature b/lib/engines/content_block_manager/features/reschedule_object.feature
index 987d540e755..5d5843b1569 100644
--- a/lib/engines/content_block_manager/features/reschedule_object.feature
+++ b/lib/engines/content_block_manager/features/reschedule_object.feature
@@ -10,13 +10,13 @@ Feature: Schedule a content object
@disable-sidekiq-test-mode
Scenario: GDS Editor immediately publishes a scheduled content object
When I am updating a content block
- Then I am asked when I want to publish the change
And I schedule the change for 7 days in the future
+ And I add an internal note
+ And I add a change note
When I review and confirm my answers are correct
When I click to view the content block
And I click to edit the schedule
And I choose to publish the change now
- And I save and continue
When I review and confirm my answers are correct
When I click to view the content block
Then the published state of the object should be shown
@@ -25,8 +25,9 @@ Feature: Schedule a content object
@disable-sidekiq-test-mode
Scenario: GDS Editor reschedules a content object
When I am updating a content block
- Then I am asked when I want to publish the change
And I schedule the change for 7 days in the future
+ And I add an internal note
+ And I add a change note
When I review and confirm my answers are correct
When I click to view the content block
And I click to edit the schedule
@@ -39,8 +40,9 @@ Feature: Schedule a content object
@disable-sidekiq-test-mode
Scenario: GDS Editor tries to reschedule a content object without choosing to schedule
When I am updating a content block
- Then I am asked when I want to publish the change
And I schedule the change for 7 days in the future
+ And I add an internal note
+ And I add a change note
When I review and confirm my answers are correct
When I click to view the content block
And I click to edit the schedule
@@ -50,8 +52,9 @@ Feature: Schedule a content object
@disable-sidekiq-test-mode
Scenario: GDS editor cancels the rescheduling of an object
When I am updating a content block
- Then I am asked when I want to publish the change
And I schedule the change for 7 days in the future
+ And I add an internal note
+ And I add a change note
When I review and confirm my answers are correct
When I click to view the content block
And I click to edit the schedule
@@ -62,8 +65,9 @@ Feature: Schedule a content object
@disable-sidekiq-test-mode
Scenario: GDS editor cancels the rescheduling of an object on the confirmation page
When I am updating a content block
- Then I am asked when I want to publish the change
And I schedule the change for 7 days in the future
+ And I add an internal note
+ And I add a change note
When I review and confirm my answers are correct
When I click to view the content block
And I click to edit the schedule
diff --git a/lib/engines/content_block_manager/features/schedule_object.feature b/lib/engines/content_block_manager/features/schedule_object.feature
index 060b3699bf2..a8bd7072442 100644
--- a/lib/engines/content_block_manager/features/schedule_object.feature
+++ b/lib/engines/content_block_manager/features/schedule_object.feature
@@ -10,8 +10,9 @@ Feature: Schedule a content object
@enable-sidekiq-test-mode
Scenario: GDS Editor schedules a content object
When I am updating a content block
- Then I am asked when I want to publish the change
And I schedule the change for 7 days in the future
+ And I add an internal note
+ And I add a change note
When I review and confirm my answers are correct
And I should be taken to the scheduled confirmation page
When I click to view the content block
@@ -21,34 +22,35 @@ Feature: Schedule a content object
@disable-sidekiq-test-mode
Scenario: GDS Editor publishes a new version of a previously scheduled content object
When I am updating a content block
- Then I am asked when I want to publish the change
And I schedule the change for 7 days in the future
+ And I add an internal note
+ And I add a change note
When I review and confirm my answers are correct
When I am updating a content block
And I choose to publish the change now
And I save and continue
+ And I add a change note
When I review and confirm my answers are correct
Then there should be no jobs scheduled
Scenario: A scheduled content object is published
When I am updating a content block
- Then I am asked when I want to publish the change
When I choose to schedule the change
And the block is scheduled and published
+ And I add an internal note
+ And I add a change note
When I review and confirm my answers are correct
Then the published state of the object should be shown
And I should see the publish event on the timeline
Scenario: GDS Editor does not provide date for scheduling
When I am updating a content block
- Then I am asked when I want to publish the change
When I choose to schedule the change
And I save and continue
Then I see the errors prompting me to provide a date and time
Scenario: GDS Editor does not provide a valid date for scheduling
When I am updating a content block
- Then I am asked when I want to publish the change
When I choose to schedule the change
And I enter an invalid date
And I save and continue
@@ -56,7 +58,6 @@ Feature: Schedule a content object
Scenario: GDS Editor provides a date in the past for scheduling
When I am updating a content block
- Then I am asked when I want to publish the change
When I choose to schedule the change
And I enter a date in the past
And I save and continue
@@ -64,8 +65,9 @@ Feature: Schedule a content object
Scenario: GDS Editor cancels after scheduling a block
When I am updating a content block
- Then I am asked when I want to publish the change
When I choose to schedule the change
And the block is scheduled and published
+ And I add an internal note
+ And I add a change note
And I click cancel
Then I am taken back to Content Block Manager home page
diff --git a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb
index a464a83d12f..292f4b3571b 100644
--- a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb
+++ b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb
@@ -92,20 +92,6 @@
expect(page).to have_link("Back", href: content_block_manager.content_block_manager_content_block_edition_path(id))
end
-Then("I should see a back link to the edit page") do
- expect(page).to have_link(
- "Back",
- href: content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document),
- )
-end
-
-Then(/^I should see a back link to the review page$/) do
- expect(page).to have_link(
- "Back",
- href: /^.*review_links.*$/,
- )
-end
-
When("I complete the form with the following fields:") do |table|
fields = table.hashes.first
@title = fields.delete("title")
@@ -374,13 +360,6 @@ def has_support_button
click_link "Edit"
end
-Then("I should see the edit form") do
- should_show_edit_form_for_email_address_content_block(
- @content_block.document.title,
- @email_address,
- )
-end
-
When("I fill out the form") do
change_details
end
@@ -511,7 +490,6 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
end
When("I review and confirm my answers are correct") do
- assert_text "Review email address"
check "By creating this content block you are confirming that, to the best of your knowledge, the details you are providing are correct."
click_on @is_scheduled ? "Schedule" : "Publish"
end
@@ -570,29 +548,13 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
end
Then(/^I (should )?see the rollup data for the dependent content$/) do |_should|
- @rollup.keys.each do |k|
- within ".rollup-details__rollup-metric.#{k}" do
- assert_text k.to_s.titleize
- within ".gem-c-glance-metric__figure" do
- assert_text @rollup[k]
- end
- end
- end
+ should_show_rollup_data
end
Then(/^I should see an error prompting me to choose an object type$/) do
assert_text I18n.t("activerecord.errors.models.content_block_manager/content_block/document.attributes.block_type.blank")
end
-Then(/^I am shown where the changes will take place$/) do
- expect(page).to have_selector("h1", text: "Preview email address")
-
- @dependent_content.each do |item|
- assert_text item["title"]
- break if item == @dependent_content.last
- end
-end
-
And("the host documents link to the draft content store") do
@dependent_content.each do |item|
expect(page).to have_selector("a.govuk-link[href='#{Plek.external_url_for('draft-origin') + item['base_path']}']", text: item["title"])
@@ -663,13 +625,10 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
click_save_and_continue
end
-Then(/^I am asked when I want to publish the change$/) do
- assert_text "Select publish date"
-end
-
Then(/^I choose to publish the change now$/) do
@is_scheduled = false
choose "Publish the edit now"
+ click_save_and_continue
end
Then("I check the block type {string}") do |checkbox_name|
@@ -784,6 +743,16 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
assert_text "There is currently a change scheduled"
end
+When("I continue after reviewing the links") do
+ click_save_and_continue
+end
+
+When(/^I add a change note$/) do
+ choose "Yes - information has been added, updated or removed"
+ fill_in "Describe the edit for users", with: "Some text"
+ click_save_and_continue
+end
+
def visit_edit_page
visit content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document)
end
@@ -892,3 +861,75 @@ def click_save_and_continue
expect(page).to have_selector(".govuk-summary-list__value", text: @user_from_signon.email)
expect(page).to have_selector(".govuk-summary-list__value", text: @user_from_signon.organisation.name)
end
+
+Then(/^I should be on the "([^"]*)" step$/) do |step|
+ case step
+ when "edit"
+ should_show_edit_form
+ when "review_links"
+ should_show_dependent_content
+ should_show_rollup_data
+ when "schedule_publishing"
+ should_show_publish_form
+ when "review"
+ should_be_on_review_step
+ when "change_note"
+ should_be_on_change_note_step
+ end
+end
+
+Then(/^I should see a back link to the "([^"]*)" step$/) do |step|
+ link = if step == "edit"
+ content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document)
+ else
+ content_block_manager.content_block_manager_content_block_workflow_path(
+ @content_block.document.editions.last,
+ step:,
+ )
+ end
+ expect(page).to have_link("Back", href: link)
+end
+
+When(/^I add an internal note$/) do
+ fill_in "Describe the change for internal users", with: "Some internal note goes here"
+ click_save_and_continue
+end
+
+def should_show_edit_form
+ should_show_edit_form_for_email_address_content_block(
+ @content_block.document.title,
+ @email_address,
+ )
+end
+
+def should_show_dependent_content
+ expect(page).to have_selector("h1", text: "Preview email address")
+
+ @dependent_content.each do |item|
+ assert_text item["title"]
+ break if item == @dependent_content.last
+ end
+end
+
+def should_show_rollup_data
+ @rollup.keys.each do |k|
+ within ".rollup-details__rollup-metric.#{k}" do
+ assert_text k.to_s.titleize
+ within ".gem-c-glance-metric__figure" do
+ assert_text @rollup[k]
+ end
+ end
+ end
+end
+
+def should_show_publish_form
+ assert_text "Select publish date"
+end
+
+def should_be_on_review_step
+ assert_text "Review email address"
+end
+
+def should_be_on_change_note_step
+ assert_text "Do users have to know the content has changed?"
+end
diff --git a/lib/engines/content_block_manager/test/factories/content_block_edition.rb b/lib/engines/content_block_manager/test/factories/content_block_edition.rb
index 77bca2df351..217d15b13d7 100644
--- a/lib/engines/content_block_manager/test/factories/content_block_edition.rb
+++ b/lib/engines/content_block_manager/test/factories/content_block_edition.rb
@@ -16,6 +16,12 @@
title { "Factory Title for Edition" }
+ internal_change_note { "Something changed" }
+
+ change_note { "Something changed publicly" }
+
+ major_change { true }
+
ContentBlockManager::ContentBlock::Schema.valid_schemas.each do |type|
trait type.to_sym do
document { build(:content_block_document, block_type: type) }
diff --git a/lib/engines/content_block_manager/test/integration/content_block/editions_test.rb b/lib/engines/content_block_manager/test/integration/content_block/editions_test.rb
index 074cfa6dac0..3bf95d2019c 100644
--- a/lib/engines/content_block_manager/test/integration/content_block/editions_test.rb
+++ b/lib/engines/content_block_manager/test/integration/content_block/editions_test.rb
@@ -119,7 +119,7 @@ class ContentBlockManager::ContentBlock::EditionsTest < ActionDispatch::Integrat
end
it "redirects to the review links step when successful" do
- redirects_to_step(ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:review_links]) do
+ redirects_to_step(:review_links) do
post content_block_manager.content_block_manager_content_block_document_editions_path(content_block_document), params: {
"content_block/edition": {
document_attributes: {
@@ -176,7 +176,7 @@ class ContentBlockManager::ContentBlock::EditionsTest < ActionDispatch::Integrat
end
it "redirects to the review step when successful" do
- redirects_to_step(ContentBlockManager::ContentBlock::Editions::WorkflowController::NEW_BLOCK_STEPS[:review]) do
+ redirects_to_step(:review) do
post content_block_manager.content_block_manager_content_block_editions_path, params: {
something: "else",
"content_block/edition": {
diff --git a/lib/engines/content_block_manager/test/integration/content_block/workflow_test.rb b/lib/engines/content_block_manager/test/integration/content_block/workflow_test.rb
index 389d282191c..bb0b55f46a2 100644
--- a/lib/engines/content_block_manager/test/integration/content_block/workflow_test.rb
+++ b/lib/engines/content_block_manager/test/integration/content_block/workflow_test.rb
@@ -30,7 +30,7 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat
describe "when creating a new content block" do
describe "when reviewing the changes" do
- let(:step) { ContentBlockManager::ContentBlock::Editions::WorkflowController::NEW_BLOCK_STEPS[:review] }
+ let(:step) { :review }
describe "#show" do
it "shows the new edition for review" do
@@ -51,7 +51,7 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat
end
describe "when the edition details have not been confirmed" do
- let(:step) { ContentBlockManager::ContentBlock::Editions::WorkflowController::NEW_BLOCK_STEPS[:review] }
+ let(:step) { :review }
describe "#update" do
it "returns to the review page" do
@@ -65,7 +65,7 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat
describe "when updating an existing content block" do
describe "when reviewing the links" do
- let(:step) { ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:review_links] }
+ let(:step) { :review_links }
describe "#show" do
it_returns_embedded_content do
@@ -83,7 +83,7 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat
end
describe "when scheduling or publishing" do
- let(:step) { ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:schedule_publishing] }
+ let(:step) { :schedule_publishing }
describe "#show" do
it "shows the form" do
@@ -96,7 +96,7 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat
describe "#update" do
describe "when choosing to publish immediately" do
- it "redirects to the review step" do
+ it "redirects to the internal note step" do
scheduled_at = {
"scheduled_publication(1i)": "",
"scheduled_publication(2i)": "",
@@ -111,12 +111,12 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat
scheduled_at:,
}
- assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :review_update)
+ assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :internal_note)
end
end
describe "when scheduling publication" do
- it "redirects to the review step" do
+ it "redirects to the internal note page" do
scheduled_at = {
"scheduled_publication(1i)": "2024",
"scheduled_publication(2i)": "01",
@@ -130,7 +130,7 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat
scheduled_at:,
}
- assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :review_update)
+ assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :internal_note)
end
end
@@ -144,6 +144,106 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat
end
end
end
+
+ describe "when updating the internal note" do
+ let(:step) { :internal_note }
+
+ describe "#show" do
+ it "shows the form" do
+ get content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:)
+
+ assert_template "content_block_manager/content_block/editions/workflow/internal_note"
+ end
+ end
+
+ describe "#update" do
+ it "adds the note and redirects" do
+ change_note = "This is my note"
+ put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:),
+ params: {
+ "content_block/edition" => {
+ "internal_change_note" => change_note,
+ },
+ }
+
+ assert_equal edition.reload.internal_change_note, change_note
+
+ assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :change_note)
+ end
+ end
+ end
+
+ describe "when updating the change note" do
+ let(:step) { :change_note }
+
+ describe "#show" do
+ it "shows the form" do
+ get content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:)
+
+ assert_template "content_block_manager/content_block/editions/workflow/change_note"
+ end
+ end
+
+ describe "#update" do
+ it "adds the note and redirects" do
+ change_note = "This is my note"
+ put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:),
+ params: {
+ "content_block/edition" => {
+ "major_change" => "1",
+ "change_note" => change_note,
+ },
+ }
+
+ assert_equal edition.reload.change_note, change_note
+ assert_equal edition.reload.major_change, true
+
+ assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :review_update)
+ end
+
+ it "shows an error if the change is major and the change note is blank" do
+ put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:),
+ params: {
+ "content_block/edition" => {
+ "major_change" => "1",
+ "change_note" => "",
+ },
+ }
+
+ assert_match(/#{I18n.t('activerecord.errors.models.content_block_manager/content_block/edition.blank', attribute: 'Change note')}/, response.body)
+ end
+
+ it "shows an error if major_change is blank" do
+ put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:),
+ params: {
+ "content_block/edition" => {
+ "major_change" => "",
+ "change_note" => "",
+ },
+ }
+
+ assert_match(/#{I18n.t('activerecord.errors.models.content_block_manager/content_block/edition.attributes.major_change.inclusion')}/, response.body)
+ end
+ end
+ end
+ end
+
+ describe "when an unknown step is provided" do
+ describe "#show" do
+ it "shows the new edition for review" do
+ get content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step: "some_random_step")
+
+ assert_response :missing
+ end
+ end
+
+ describe "#update" do
+ it "posts the new edition to the Publishing API and marks edition as published" do
+ put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step: "some_random_step")
+
+ assert_response :missing
+ end
+ end
end
end
diff --git a/lib/engines/content_block_manager/test/unit/app/models/content_block_edition_test.rb b/lib/engines/content_block_manager/test/unit/app/models/content_block_edition_test.rb
index f51314d78fd..c7f559a903f 100644
--- a/lib/engines/content_block_manager/test/unit/app/models/content_block_edition_test.rb
+++ b/lib/engines/content_block_manager/test/unit/app/models/content_block_edition_test.rb
@@ -11,6 +11,9 @@ class ContentBlockManager::ContentBlockEditionTest < ActiveSupport::TestCase
let(:title) { "Edition title" }
let(:creator) { create(:user) }
let(:organisation) { create(:organisation) }
+ let(:internal_change_note) { "My internal change note" }
+ let(:change_note) { "My internal change note" }
+ let(:major_change) { true }
let(:content_block_edition) do
ContentBlockManager::ContentBlock::Edition.new(
@@ -18,11 +21,15 @@ class ContentBlockManager::ContentBlockEditionTest < ActiveSupport::TestCase
updated_at:,
details:,
document_attributes: {
+ sluggable_string: "Something",
block_type: "email_address",
},
creator:,
organisation_id: organisation.id.to_s,
title:,
+ internal_change_note:,
+ change_note:,
+ major_change:,
)
end
@@ -39,6 +46,9 @@ class ContentBlockManager::ContentBlockEditionTest < ActiveSupport::TestCase
assert_equal updated_at, content_block_edition.updated_at
assert_equal details, content_block_edition.details
assert_equal title, content_block_edition.title
+ assert_equal internal_change_note, content_block_edition.internal_change_note
+ assert_equal change_note, content_block_edition.change_note
+ assert_equal major_change, content_block_edition.major_change
end
it "persists the block type to the document" do
@@ -97,6 +107,37 @@ class ContentBlockManager::ContentBlockEditionTest < ActiveSupport::TestCase
assert content_block_edition.errors.full_messages.include?("Title cannot be blank")
end
+ describe "change note validation" do
+ it "validates the presence of a change note if the change is major" do
+ content_block_edition.change_note = nil
+ content_block_edition.major_change = true
+
+ assert_invalid content_block_edition, context: :change_note
+ assert content_block_edition.errors.full_messages.include?("Change note cannot be blank")
+ end
+
+ it "is valid when the change is major and a change note is provided" do
+ content_block_edition.change_note = "something"
+ content_block_edition.major_change = true
+
+ assert_valid content_block_edition, context: :change_note
+ end
+
+ it "validates the presence of the major_change boolean" do
+ content_block_edition.major_change = nil
+
+ assert_invalid content_block_edition, context: :change_note
+ assert content_block_edition.errors.full_messages.include?("Select if users have to know the content has changed")
+ end
+
+ it "is valid when the change is minor and a change note is not provided" do
+ content_block_edition.change_note = nil
+ content_block_edition.major_change = false
+
+ assert_valid content_block_edition, context: :change_note
+ end
+ end
+
it "adds a creator and first edition author for new records" do
content_block_edition.save!
content_block_edition.reload
diff --git a/test/support/model_helpers.rb b/test/support/model_helpers.rb
index 5c1ad00f31f..6d41a814609 100644
--- a/test/support/model_helpers.rb
+++ b/test/support/model_helpers.rb
@@ -1,12 +1,12 @@
module ModelHelpers
extend ActiveSupport::Concern
- def assert_valid(model)
- assert model.valid?, "Expected #{model} to be valid."
+ def assert_valid(model, context: nil)
+ assert model.valid?(context), "Expected #{model} to be valid."
end
- def assert_invalid(model)
- assert_not model.valid?, "Expected #{model} not to be valid."
+ def assert_invalid(model, context: nil)
+ assert_not model.valid?(context), "Expected #{model} not to be valid."
end
module ClassMethods