From 960b829ece2a8a81f45bad719d4ecfc5c70d081f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 23 Apr 2021 11:33:26 +1000 Subject: [PATCH] Link to last uploaded Terms of service --- app/helpers/terms_and_conditions_helper.rb | 2 +- app/models/terms_of_service_file.rb | 4 ++++ spec/models/terms_of_service_file_spec.rb | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/helpers/terms_and_conditions_helper.rb b/app/helpers/terms_and_conditions_helper.rb index 74b9bb7df0..59a9e5cdb2 100644 --- a/app/helpers/terms_and_conditions_helper.rb +++ b/app/helpers/terms_and_conditions_helper.rb @@ -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 diff --git a/app/models/terms_of_service_file.rb b/app/models/terms_of_service_file.rb index b19b9ea84d..418a93ca71 100644 --- a/app/models/terms_of_service_file.rb +++ b/app/models/terms_of_service_file.rb @@ -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 diff --git a/spec/models/terms_of_service_file_spec.rb b/spec/models/terms_of_service_file_spec.rb index f66322f107..3cff542b3a 100644 --- a/spec/models/terms_of_service_file_spec.rb +++ b/spec/models/terms_of_service_file_spec.rb @@ -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