Skip to content

Commit

Permalink
Controls: Add ability to delete controls
Browse files Browse the repository at this point in the history
- Add `ControlsController#destroy` and translations
  • Loading branch information
csutter committed Feb 3, 2025
1 parent 0256148 commit 8933f64
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/controllers/controls_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ControlsController < ApplicationController
before_action :set_control, only: %i[show edit update]
before_action :set_control, only: %i[show edit update destroy]

def index
@controls = Control.order(:display_name)
Expand Down Expand Up @@ -33,6 +33,14 @@ def update
end
end

def destroy
if @control.destroy
redirect_to controls_path, notice: t(".success")
else
redirect_to @control, alert: t(".failure")
end
end

private

def set_control
Expand Down
5 changes: 5 additions & 0 deletions app/views/controls/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
href: edit_control_path(@control),
inline_layout: true
} %>
<%= delete_button(
t("common.buttons.delete", model_name: t_model_name),
@control,
is_inline: true
) %>
</div>

<%= render "govuk_publishing_components/components/summary_list", {
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ en:
success: The control was successfully created.
update:
success: The control was successfully updated.
destroy:
success: The control was successfully deleted.
failure: The control could not be deleted.

recommended_links:
index:
Expand Down
15 changes: 15 additions & 0 deletions spec/system/controls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

then_the_control_has_been_updated
and_i_can_see_the_updated_boost_control_details

when_i_choose_to_delete_the_control
then_the_control_has_been_deleted
end

scenario "Managing filter controls" do
Expand All @@ -35,6 +38,9 @@

then_the_control_has_been_updated
and_i_can_see_the_updated_filter_control_details

when_i_choose_to_delete_the_control
then_the_control_has_been_deleted
end

def given_several_controls_exist
Expand Down Expand Up @@ -131,4 +137,13 @@ def and_i_can_see_the_updated_filter_control_details
expect(page).to have_content("Name My updated filter control")
expect(page).to have_content("Filter expression is_really_cool = 999")
end

def when_i_choose_to_delete_the_control
click_button "Delete control"
end

def then_the_control_has_been_deleted
expect(page).to have_content("control was successfully deleted")
expect(Control.count).to eq(0)
end
end

0 comments on commit 8933f64

Please sign in to comment.