Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(908) Stop continue editing from removing existing embedded objects #9948

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ module Workflow::UpdateMethods

def update_draft
@content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
@content_block_edition.assign_attributes(edition_params.except(:creator, :document_attributes))

@content_block_edition.assign_attributes(
title: edition_params[:title],
organisation_id: edition_params[:organisation_id],
instructions_to_publishers: edition_params[:instructions_to_publishers],
details: @content_block_edition.details.merge(edition_params[:details]),
)
@content_block_edition.save!

if @content_block_edition.document.is_new_block?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module ContentBlock::Edition::HasLeadOrganisation
end

def organisation_id=(organisation_id)
if organisation_id.empty?
if organisation_id.blank?
self.edition_organisation = nil
else
edition_organisation = build_edition_organisation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% content_for :page_full_width, true %>
<% content_for :page_title, @content_block_document.title %>
<% content_for :back_link do %>
<%= render "govuk_publishing_components/components/back_link", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,14 @@ Feature: Edit a pension object
When I click to view the content block
Then the edition should have been updated successfully
And I should see details of my "rate"

Scenario: GDS editor sees notification about an in-progress draft
When I visit the Content Block Manager home page
And I click to view the document
And I click to edit the "pension"
And I fill out the form
And I click the cancel link
And I click to save and come back later
When I click on the link to continue editing
And I click save
Then I should see the rates for that block
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,33 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat
params: {
"content_block/edition" => {
"title" => "New title",
"organisation_id" => organisation.id,
"details" => {
"foo" => "bar",
},
},
}

assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :review_links)

assert_equal edition.reload.title, "New title"
assert_equal edition.reload.details["foo"], "bar"
assert_equal edition.reload.details["bar"], "Bar text"
end

assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :review_links)
it "updates the block with an empty string if a details field is blank" do
put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:),
params: {
"content_block/edition" => {
"title" => "New title",
"organisation_id" => organisation.id,
"details" => {
"foo" => "",
},
},
}

assert_equal edition.reload.details["foo"], ""
end

it "updates the block and redirects to the review page if editing a new block" do
Expand All @@ -156,16 +173,18 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat
params: {
"content_block/edition" => {
"title" => "New title",
"organisation_id" => organisation.id,
"details" => {
"foo" => "bar",
},
},
}

assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :review)

assert_equal edition.reload.title, "New title"
assert_equal edition.reload.details["foo"], "bar"

assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :review)
assert_equal edition.reload.details["bar"], "Bar text"
end

it "shows an error if a required field is blank" do
Expand Down
Loading