Link to last uploaded Terms of service

This commit is contained in:
Maikel Linke
2021-04-23 11:33:26 +10:00
parent 23999c96bf
commit 960b829ece
3 changed files with 19 additions and 1 deletions

View File

@@ -2,7 +2,7 @@
module TermsAndConditionsHelper
def link_to_platform_terms
link_to(t("terms_of_service"), Spree::Config.footer_tos_url, target: "_blank")
link_to(t("terms_of_service"), TermsOfServiceFile.current_url, target: "_blank")
end
def render_terms_and_conditions

View File

@@ -9,4 +9,8 @@ class TermsOfServiceFile < ApplicationRecord
def self.current
order(:id).last
end
def self.current_url
current&.attachment&.url || Spree::Config.footer_tos_url
end
end

View File

@@ -19,4 +19,18 @@ describe TermsOfServiceFile do
expect(TermsOfServiceFile.current).to eq existing.last
end
end
describe ".current_url" do
let(:subject) { TermsOfServiceFile.current_url }
it "points to the old default" do
expect(subject).to eq "/Terms-of-service.pdf"
end
it "points to the last uploaded file with timestamp parameter" do
file = TermsOfServiceFile.create!(attachment: pdf)
expect(subject).to match /^\/system\/terms_of_service_files\/attachments.*Terms-of-service\.pdf\?\d+$/
end
end
end