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 ef8ac55ff57..baec52b1514 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 @@ -96,6 +96,12 @@ def review_update_url ) end + def validate_scheduled_edition + @content_block_edition.assign_attributes(scheduled_publication_params) + @content_block_edition.assign_attributes(state: "scheduled") + raise ActiveRecord::RecordInvalid unless @content_block_edition.valid? + end + def review_update @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id]) @@ -103,9 +109,7 @@ def review_update @content_block_edition.errors.add(:schedule_publishing, "cannot be blank") raise ActiveRecord::RecordInvalid, @content_block_edition elsif params[:schedule_publishing] == "schedule" - @content_block_edition.update!(scheduled_publication_params) - @content_block_edition.schedule! - raise ActiveRecord::RecordInvalid, @content_block_edition if @content_block_edition.errors.any? + validate_scheduled_edition end @url = review_update_url diff --git a/lib/engines/content_block_manager/features/edit_object.feature b/lib/engines/content_block_manager/features/edit_object.feature index 39d66674e5a..d952e862d90 100644 --- a/lib/engines/content_block_manager/features/edit_object.feature +++ b/lib/engines/content_block_manager/features/edit_object.feature @@ -44,7 +44,7 @@ Feature: Edit a content object 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 publishing + 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 When I click the first edit link @@ -58,6 +58,18 @@ Feature: Edit a content object 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 + When I click the first edit link + When I fill out the form + When I save and continue + When I choose to publish the change now + And I save and continue + And I click cancel + Then I am taken back to Content Block Manager home page + And no draft Content Block Edition has been created + Scenario: GDS editor sees validation errors for missing fields And a schema "email_address" exists with the following fields: | field | type | format | required | diff --git a/lib/engines/content_block_manager/features/schedule_object.feature b/lib/engines/content_block_manager/features/schedule_object.feature index 03b4e799599..7b36d01f7ea 100644 --- a/lib/engines/content_block_manager/features/schedule_object.feature +++ b/lib/engines/content_block_manager/features/schedule_object.feature @@ -124,3 +124,11 @@ Feature: Schedule a content object And I enter a date in the past And I save and continue Then I see the errors informing me the date must be in the future + + 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 click cancel + Then I am taken back to Content Block Manager home page diff --git a/lib/engines/content_block_manager/test/unit/app/models/content_block_edition/workflow_test.rb b/lib/engines/content_block_manager/test/unit/app/models/content_block_edition/workflow_test.rb index 97cdf817fbe..29ac11d1007 100644 --- a/lib/engines/content_block_manager/test/unit/app/models/content_block_edition/workflow_test.rb +++ b/lib/engines/content_block_manager/test/unit/app/models/content_block_edition/workflow_test.rb @@ -6,12 +6,6 @@ class ContentBlockManager::WorkflowTest < ActiveSupport::TestCase assert edition.draft? end - test "publishing a draft edition transitions it into the published state" do - edition = create(:content_block_edition, document: create(:content_block_document, block_type: "email_address")) - edition.publish! - assert edition.published? - end - test "publishing a scheduled edition transitions it into the published state" do edition = create(:content_block_edition, document: create(