Add delete method to terms of service files

This commit is contained in:
Maikel Linke
2021-04-22 14:30:21 +10:00
parent 3bee9cb951
commit 690118c2bd
4 changed files with 20 additions and 1 deletions

View File

@@ -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

View File

@@ -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")

View File

@@ -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"

View File

@@ -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