diff --git a/app/controllers/admin/financial_accounts_controller.rb b/app/controllers/admin/financial_accounts_controller.rb index e63c0ca..4049df4 100644 --- a/app/controllers/admin/financial_accounts_controller.rb +++ b/app/controllers/admin/financial_accounts_controller.rb @@ -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 diff --git a/app/views/admin/financial_accounts/show.html.haml b/app/views/admin/financial_accounts/show.html.haml index dbb749b..b214461 100644 --- a/app/views/admin/financial_accounts/show.html.haml +++ b/app/views/admin/financial_accounts/show.html.haml @@ -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 } diff --git a/config/routes.rb b/config/routes.rb index 57d3439..dbc68e5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] diff --git a/spec/system/financial_accounts/admin_deletes_financial_account_spec.rb b/spec/system/financial_accounts/admin_deletes_financial_account_spec.rb new file mode 100644 index 0000000..1a80226 --- /dev/null +++ b/spec/system/financial_accounts/admin_deletes_financial_account_spec.rb @@ -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