-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1659 from alphagov/ldeb-refactor-page-delete
Refactor controller actions and views for page delete confirmation
- Loading branch information
Showing
14 changed files
with
234 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
class Forms::DeleteConfirmationInput < ConfirmActionInput | ||
def to_partial_path | ||
"input_objects/forms/delete_confirmation_input" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
<% set_page_title(title_with_error_prefix(@confirm_deletion_legend, @delete_confirmation_input.errors.any?)) %> | ||
<% content_for :back_link, govuk_back_link_to(@back_url) %> | ||
<%= form_with(model: @delete_confirmation_input, url: @url, method: 'delete') do |f| %> | ||
<% if @delete_confirmation_input&.errors.any? %> | ||
<%= f.govuk_error_summary %> | ||
<% end %> | ||
<span class="govuk-caption-l"><%= @item_name %></span> | ||
<%= f.govuk_collection_radio_buttons :confirm, | ||
@delete_confirmation_input.values, ->(option) { option }, ->(option) { t('helpers.label.confirm_action_input.options.' + "#{option}") }, | ||
legend: { text: @confirm_deletion_legend, size: 'l', tag: 'h1' }, | ||
hint: {text: @confirm_deletion_live_form} %> | ||
|
||
<%= f.govuk_submit %> | ||
<% end %> | ||
<%= render( | ||
@delete_confirmation_input, | ||
url: @url, | ||
caption_text: @item_name, | ||
legend_text: @confirm_deletion_legend, | ||
) %> |
12 changes: 12 additions & 0 deletions
12
app/views/input_objects/forms/_delete_confirmation_input.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%= form_with(model: delete_confirmation_input, url:, method: 'delete') do |f| %> | ||
<% if delete_confirmation_input&.errors.any? %> | ||
<%= f.govuk_error_summary %> | ||
<% end %> | ||
<span class="govuk-caption-l"><%= caption_text %></span> | ||
<%= f.govuk_collection_radio_buttons :confirm, | ||
delete_confirmation_input.values, ->(option) { option }, ->(option) { t('helpers.label.confirm_action_input.options.' + "#{option}") }, | ||
legend: { text: legend_text, size: 'l', tag: 'h1' } | ||
%> | ||
|
||
<%= f.govuk_submit %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<% set_page_title(title_with_error_prefix(@confirm_deletion_legend, @delete_confirmation_input.errors.any?)) %> | ||
<% content_for :back_link, govuk_back_link_to(@back_url) %> | ||
|
||
<%= render( | ||
@delete_confirmation_input, | ||
url: @url, | ||
caption_text: @item_name, | ||
legend_text: @confirm_deletion_legend, | ||
hint_text: nil, | ||
) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
spec/views/forms/delete_confirmation/delete.html.erb_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "forms/delete_confirmation/delete" do | ||
let(:form) { build :form, id: 1, name: "Test form" } | ||
|
||
before do | ||
assign(:back_url, form_path(form_id: 1)) | ||
assign(:confirm_deletion_legend, "Are you sure you want to delete this draft?") | ||
assign(:delete_confirmation_input, Forms::DeleteConfirmationInput.new) | ||
assign(:item_name, form.name) | ||
assign(:url, destroy_form_path(form_id: 1)) | ||
|
||
render | ||
end | ||
|
||
it "has a page title" do | ||
expect(view.content_for(:title)).to include "Are you sure you want to delete this draft?" | ||
end | ||
|
||
it "has a heading" do | ||
expect(rendered).to have_css "h1", text: "Are you sure you want to delete this draft?" | ||
end | ||
|
||
it "has a heading caption with the question text" do | ||
expect(rendered).to have_css ".govuk-caption-l", text: "Test form" | ||
end | ||
|
||
it "has a back link to the form page" do | ||
expect(view.content_for(:back_link)).to have_link "Back", href: "/forms/1" | ||
end | ||
|
||
it "has a delete confirmation input to confirm deletion of the form" do | ||
expect(rendered).to render_template "input_objects/forms/_delete_confirmation_input" | ||
end | ||
|
||
describe "delete confirmation input" do | ||
it "posts the confirm value to the destroy action" do | ||
expect(rendered).to have_element "form", action: "/forms/1/delete", method: "post" | ||
end | ||
end | ||
end |
Oops, something went wrong.