Skip to content

Commit

Permalink
validate state for edition under review
Browse files Browse the repository at this point in the history
during the review stage, we want to check the
scheduled values from the previous page are valid,
but not yet put the edition into a scheduled or
published state.

here we validate there are no errors by updating
the edition via the `assign_attributes` method which
does not save the changes to the db.
  • Loading branch information
Harriethw committed Dec 17, 2024
1 parent 3f6d7f2 commit 9671e13
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,20 @@ 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])

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.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
Expand Down
14 changes: 13 additions & 1 deletion lib/engines/content_block_manager/features/edit_object.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9671e13

Please sign in to comment.