Skip to content

Commit

Permalink
Merge pull request #1534 from alphagov/add-delete-app-functionality
Browse files Browse the repository at this point in the history
Add functionality to delete retired apps
  • Loading branch information
deborahchua authored Jul 26, 2024
2 parents 23b63ed + 1bce3cf commit e7ed646
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//= require_tree .
//= require govuk_publishing_components/dependencies
//= require govuk_publishing_components/all_components

//= require rails-ujs
7 changes: 6 additions & 1 deletion app/controllers/applications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ApplicationsController < ApplicationController
before_action :find_application, only: %i[show edit update deploy stats]
before_action :find_application, only: %i[show edit update deploy stats destroy]

include ActionView::Helpers::DateHelper

Expand Down Expand Up @@ -74,6 +74,11 @@ def update
end
end

def destroy
@application.destroy!
redirect_to applications_path, notice: "Successfully deleted application"
end

private

def find_application
Expand Down
12 changes: 12 additions & 0 deletions app/views/applications/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,17 @@

<%= render "govuk_publishing_components/components/button", {
text: @application.new_record? ? "Create Application" : "Update application",
margin_bottom: 4,
} %>
<% end %>

<% unless current_page?(action: 'new') %>
<%= form_for @application, method: :delete do |f| %>
<%= render "govuk_publishing_components/components/button", {
text: "Delete application",
destructive: true,
data_attributes: { confirm: "Are you sure you wish to delete this application?" },
info_text: "You can remove this app if it is retired.",
} %>
<% end %>
<% end %>
18 changes: 18 additions & 0 deletions test/functional/applications_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,24 @@ class ApplicationsControllerTest < ActionController::TestCase
end
end

context "POST destroy" do
setup do
stub_request(:get, Repo::REPO_JSON_URL).to_return(status: 200)
@app = FactoryBot.create(:application)
end

should "delete the application" do
assert_difference "Application.count", -1 do
post :destroy, params: { id: @app.id }
end
end

should "redirect to the index page" do
post :destroy, params: { id: @app.id }
assert_redirected_to applications_path
end
end

private

def random_sha
Expand Down

0 comments on commit e7ed646

Please sign in to comment.