From 690118c2bda8dcce838df8bf15d0f559b2e2182c Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 22 Apr 2021 14:30:21 +1000 Subject: [PATCH] Add delete method to terms of service files --- .../admin/terms_of_service_files_controller.rb | 5 +++++ .../admin/terms_of_service_files/show.html.haml | 1 + config/locales/en.yml | 1 + .../configuration/terms_of_service_files_spec.rb | 14 +++++++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/terms_of_service_files_controller.rb b/app/controllers/admin/terms_of_service_files_controller.rb index e1e42e88c2..e3cc71a9db 100644 --- a/app/controllers/admin/terms_of_service_files_controller.rb +++ b/app/controllers/admin/terms_of_service_files_controller.rb @@ -17,6 +17,11 @@ module Admin redirect_to main_app.admin_terms_of_service_files_path end + def destroy + TermsOfServiceFile.current.destroy! + redirect_to main_app.admin_terms_of_service_files_path + end + private # Needed by Spree::Admin::BaseController#authorize_admin or it diff --git a/app/views/admin/terms_of_service_files/show.html.haml b/app/views/admin/terms_of_service_files/show.html.haml index 199abc49a1..6e4a37532c 100644 --- a/app/views/admin/terms_of_service_files/show.html.haml +++ b/app/views/admin/terms_of_service_files/show.html.haml @@ -3,6 +3,7 @@ - if @current_file = link_to t(".terms_of_service"), @current_file.attachment.url + = link_to t(".delete"), main_app.admin_terms_of_service_files_path, method: "delete" - else = t(".no_files") diff --git a/config/locales/en.yml b/config/locales/en.yml index f0a2a28379..8c5f0120e5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -453,6 +453,7 @@ en: title: "Terms of Service files" no_files: "No terms of services have been uploaded yet." terms_of_service: "Terms of Service" + delete: "Delete" number_localization: number_localization_settings: "Number Localization Settings" enable_localized_number: "Use the international thousand/decimal separator logic" diff --git a/spec/features/admin/configuration/terms_of_service_files_spec.rb b/spec/features/admin/configuration/terms_of_service_files_spec.rb index 9c69006123..def51d4aad 100644 --- a/spec/features/admin/configuration/terms_of_service_files_spec.rb +++ b/spec/features/admin/configuration/terms_of_service_files_spec.rb @@ -6,6 +6,8 @@ describe "Terms of Service files" do include AuthenticationHelper describe "as admin" do + let(:test_file_path) { "public/Terms-of-service.pdf" } + before { login_as_admin } it "can be reached via Configuration" do @@ -16,7 +18,7 @@ describe "Terms of Service files" do it "can be uploaded" do visit admin_terms_of_service_files_path - attach_file "Attachment", Rails.root.join("public/Terms-of-service.pdf") + attach_file "Attachment", Rails.root.join(test_file_path) click_button "Create Terms of service file" expect(page).to have_link "Terms of Service" @@ -26,5 +28,15 @@ describe "Terms of Service files" do visit new_admin_terms_of_service_files_path expect(page).to have_button "Create Terms of service file" end + + it "can delete the current file" do + attachment = File.open(Rails.root.join(test_file_path)) + TermsOfServiceFile.create!(attachment: attachment) + + visit admin_terms_of_service_files_path + click_link "Delete" + + expect(page).to have_content "No terms of services have been uploaded yet." + end end end