Skip to content

Commit

Permalink
Admin deletes financial account
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured authored and github-actions[bot] committed Feb 18, 2024
1 parent ff6af87 commit be5201d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/controllers/admin/financial_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def update
end
end

def destroy
financial_account.destroy
redirect_to admin_financial_accounts_path
end

private

def financial_account_params
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/financial_accounts/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

%p= link_to "Edit Financial Account", edit_admin_financial_account_path(financial_account)

%p= link_to "Delete Financial Account", admin_financial_account_path(action: :delete, id: financial_account.id), data: {turbo_method: :delete, turbo_confirm: 'Are you sure?'}

= render partial: "attrs_table", locals: { attrs: financial_account.table_attrs }
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace :admin do
resources :books, only: %i[create edit new update]
resources :csv_uploads, only: %i[create index new show]
resources :financial_accounts, only: %i[create edit index new show update]
resources :financial_accounts
resources :gift_ideas
resources :hooks, only: %i[create edit index]
resources :post_bin_requests, only: %i[index show]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "rails_helper"

describe "Admin deletes FinancialAccount" do
include_context "admin password matches"

let(:financial_account) { FactoryBot.create(:financial_account) }

scenario "cancels delete" do
visit "/admin/financial_accounts/#{financial_account.id}"

dismiss_confirm { click_on "Delete Financial Account" }

expect(FinancialAccount.count).to eq 1
expect(current_path).to eq admin_financial_account_path(financial_account)
end

scenario "confirms delete" do
visit "/admin/financial_accounts/#{financial_account.id}"

accept_confirm { click_on "Delete Financial Account" }

expect(page).to have_css "h1", text: "Financial Accounts"

expect(FinancialAccount.count).to eq 0
expect(current_path).to eq admin_financial_accounts_path
end
end

0 comments on commit be5201d

Please sign in to comment.