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 d19046fea89..f4ab15cd4a3 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 @@ -49,4 +49,27 @@ def support_url def prepend_views prepend_view_path Rails.root.join("lib/engines/content_block_manager/app/views") end + + def validate_scheduled_edition + if params[:schedule_publishing].blank? + @content_block_edition.errors.add(:schedule_publishing, "cannot be blank") + raise ActiveRecord::RecordInvalid, @content_block_edition + elsif params[:schedule_publishing] == "schedule" + @content_block_edition.assign_attributes(scheduled_publication_params) + @content_block_edition.assign_attributes(state: "scheduled") + raise ActiveRecord::RecordInvalid unless @content_block_edition.valid? + end + end + + def review_update_url + schedule_publishing = params[:schedule_publishing] + scheduled_at = scheduled_publication_params.to_h + + content_block_manager.content_block_manager_content_block_workflow_path( + @content_block_edition, + step: ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:review_update], + schedule_publishing:, + scheduled_at:, + ) + end end 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 f75c7a9531e..7f8283ba5c8 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 @@ -9,18 +9,11 @@ def edit def update document = ContentBlockManager::ContentBlock::Document.find(params[:document_id]) @content_block_edition = document.latest_edition - validate_update - end + validate_scheduled_edition -private + @url = review_update_url - def validate_update - if params[:schedule_publishing].blank? - @content_block_edition.errors.add(:schedule_publishing, "cannot be blank") - raise ActiveRecord::RecordInvalid, @content_block_edition - else - schedule_or_publish - end + render "content_block_manager/content_block/editions/workflow/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 baec52b1514..1b282ffdd3f 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 @@ -84,33 +84,10 @@ def review_url ) end - def review_update_url - schedule_publishing = params[:schedule_publishing] - scheduled_at = scheduled_publication_params.to_h - - content_block_manager.content_block_manager_content_block_workflow_path( - @content_block_edition, - step: ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:review_update], - schedule_publishing:, - scheduled_at:, - ) - 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]) - if params[:schedule_publishing].blank? - @content_block_edition.errors.add(:schedule_publishing, "cannot be blank") - raise ActiveRecord::RecordInvalid, @content_block_edition - elsif params[:schedule_publishing] == "schedule" - validate_scheduled_edition - end + validate_scheduled_edition @url = review_update_url diff --git a/lib/engines/content_block_manager/features/reschedule_object.feature b/lib/engines/content_block_manager/features/reschedule_object.feature new file mode 100644 index 00000000000..9e4ba344bd7 --- /dev/null +++ b/lib/engines/content_block_manager/features/reschedule_object.feature @@ -0,0 +1,48 @@ +Feature: Schedule a content object + Background: + Given I am a GDS admin + And the organisation "Ministry of Example" exists + And a schema "email_address" exists with the following fields: + | field | type | format | required | + | email_address | string | email | true | + And an email address content block has been created + + @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 + 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 + And there should be no jobs scheduled + + @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 + 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 schedule the change for 5 days in the future + When I review and confirm my answers are correct + When I click to view the content block + Then I should see the scheduled date on the object + And there should only be one job scheduled + + @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 + 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 save and continue + Then I see the error message "Schedule publishing cannot be blank" diff --git a/lib/engines/content_block_manager/features/schedule_object.feature b/lib/engines/content_block_manager/features/schedule_object.feature index 7b36d01f7ea..060b3699bf2 100644 --- a/lib/engines/content_block_manager/features/schedule_object.feature +++ b/lib/engines/content_block_manager/features/schedule_object.feature @@ -18,57 +18,6 @@ Feature: Schedule a content object And I should see the scheduled date on the object And I should see the scheduled event on the timeline - @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 - 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 click to view the content block - Then the published state of the object should be shown - And there should be no jobs scheduled - - @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 - 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 schedule the change for 5 days in the future - When I click to view the content block - Then I should see the scheduled date on the object - And there should only be one job scheduled - - @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 - 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 save and continue - Then I see the error message "Schedule publishing cannot be blank" - - @disable-sidekiq-test-mode - Scenario: GDS Editor tries to reschedule a content object with an invalid date - 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 - When I review and confirm my answers are correct - When I click to view the content block - And I click to edit the schedule - When I choose to schedule the change - And I enter an invalid date - And I save and continue - Then I see the errors informing me the date is invalid - @disable-sidekiq-test-mode Scenario: GDS Editor publishes a new version of a previously scheduled content object When I am updating a content block @@ -81,18 +30,6 @@ Feature: Schedule a content object When I review and confirm my answers are correct Then there should be no jobs scheduled - @disable-sidekiq-test-mode - Scenario: GDS Editor schedules a new version of a previously scheduled content block - 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 - 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 schedule the change for 5 days in the future - When I click to view the content block - Then there should only be one job 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