Skip to content

Commit

Permalink
Merge pull request #9747 from alphagov/content-modelling/748-add-revi…
Browse files Browse the repository at this point in the history
…ew-to-schedule-edit

Content modelling/748 add review page to the reschedule journey
  • Loading branch information
Harriethw authored Dec 18, 2024
2 parents 3f0a6e6 + 621babe commit 10bff29
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
63 changes: 0 additions & 63 deletions lib/engines/content_block_manager/features/schedule_object.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 10bff29

Please sign in to comment.