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

(933) Fix back link when creating a new object #9966

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 @@ -69,23 +69,24 @@ def confirmation
end

def back_path
if current_step.name == "review" && @content_block_edition.document.is_new_block?
content_block_manager.content_block_manager_content_block_documents_path
else
return nil unless previous_step
step = is_reviewing_new_block? ? :edit_draft : previous_step.name
return nil unless step

content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
step: previous_step.name,
)
end
content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
step:,
)
end
included do
helper_method :back_path
end

private

def is_reviewing_new_block?
current_step.name == :review && @content_block_edition.document.is_new_block?
end

def embedded_objects(subschema_name)
@subschema = @schema.subschema(subschema_name)
@step_name = current_step.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Feature: Create a content object
| title | email_address | department | organisation | instructions_to_publishers |
| my email address | [email protected] | Somewhere | Ministry of Example | this is important |
Then I am asked to review my answers
And I review and confirm my answers are correct
And I should see a back link to the "edit_draft" step
When I review and confirm my answers are correct
Then the edition should have been created successfully
And I should be taken to the confirmation page for a new block

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
end

Then(/^I should see a back link to the "([^"]*)" step$/) do |step|
@content_block ||= ContentBlockManager::ContentBlock::Edition.last
link = if step == "edit"
content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ class Workflow::ShowMethodsTest < ActionDispatch::IntegrationTest
describe "when editing an existing block" do
let(:is_new_block) { true }

it "returns the homepage link for the review step" do
current_step = mock("Workflow::Step", name: "review")
it "returns the edit draft step" do
current_step = mock("Workflow::Step", name: :review)
previous_step = mock("Workflow::Step")

test_class = ShowMethodsTestClass.new(current_step:, previous_step:, content_block_edition:)

assert_equal test_class.back_path, content_block_manager.content_block_manager_content_block_documents_path
assert_equal test_class.back_path, content_block_manager.content_block_manager_content_block_workflow_path(
content_block_edition,
step: :edit_draft,
)
end
end
end
Expand Down