diff options
| -rw-r--r-- | app/helpers/admin_helper.rb | 6 | ||||
| -rw-r--r-- | app/views/layouts/admin.html.erb | 8 | ||||
| -rw-r--r-- | test/models/helpers/admin_helper_test.rb | 10 |
3 files changed, 20 insertions, 4 deletions
diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 08336ef..1e84620 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb | |||
| @@ -8,4 +8,10 @@ module AdminHelper | |||
| 8 | link_to raw('<span class="inactive">English</span>'), url_for(params.permit(:locale, :page_path).to_h.merge('locale' => 'de')) | 8 | link_to raw('<span class="inactive">English</span>'), url_for(params.permit(:locale, :page_path).to_h.merge('locale' => 'de')) |
| 9 | end | 9 | end |
| 10 | end | 10 | end |
| 11 | |||
| 12 | def mtime_busted_path(path) | ||
| 13 | file = Rails.public_path.join(path.sub(%r{\A/}, "")) | ||
| 14 | raise "Static asset not found for cache-busting: #{path} (looked for #{file})" unless File.exist?(file) | ||
| 15 | "#{path}?v=#{File.mtime(file).to_i}" | ||
| 16 | end | ||
| 11 | end | 17 | end |
diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 8bbc0d5..0856a0f 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb | |||
| @@ -10,10 +10,10 @@ | |||
| 10 | <%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %> | 10 | <%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %> |
| 11 | <%= javascript_include_tag 'admin_bundle' %> | 11 | <%= javascript_include_tag 'admin_bundle' %> |
| 12 | <%= tinymce_assets %> | 12 | <%= tinymce_assets %> |
| 13 | <link rel="stylesheet" href="/stylesheets/admin.css"> | 13 | <link rel="stylesheet" href="<%= mtime_busted_path('/stylesheets/admin.css') %>"> |
| 14 | <script src="/javascripts/admin_search.js"></script> | 14 | <script src="<%= mtime_busted_path('/javascripts/admin_search.js') %>"></script> |
| 15 | <script src="/javascripts/admin_interface.js"></script> | 15 | <script src="<%= mtime_busted_path('/javascripts/admin_interface.js') %>"></script> |
| 16 | <script src="/javascripts/related_assets.js"></script> | 16 | <script src="<%= mtime_busted_path('/javascripts/related_assets.js') %>"></script> |
| 17 | <script> | 17 | <script> |
| 18 | var ADMIN_SEARCH_URL = "<%= admin_search_path %>"; | 18 | var ADMIN_SEARCH_URL = "<%= admin_search_path %>"; |
| 19 | var ADMIN_MENU_SEARCH_URL = "<%= admin_menu_search_path %>"; | 19 | var ADMIN_MENU_SEARCH_URL = "<%= admin_menu_search_path %>"; |
diff --git a/test/models/helpers/admin_helper_test.rb b/test/models/helpers/admin_helper_test.rb index 23d9f40..94e9861 100644 --- a/test/models/helpers/admin_helper_test.rb +++ b/test/models/helpers/admin_helper_test.rb | |||
| @@ -1,4 +1,14 @@ | |||
| 1 | require 'test_helper' | 1 | require 'test_helper' |
| 2 | 2 | ||
| 3 | class AdminHelperTest < ActionView::TestCase | 3 | class AdminHelperTest < ActionView::TestCase |
| 4 | test "mtime_busted_path appends the file's real mtime as a query param" do | ||
| 5 | path = "/stylesheets/admin.css" | ||
| 6 | expected_mtime = File.mtime(Rails.public_path.join("stylesheets/admin.css")).to_i | ||
| 7 | |||
| 8 | assert_equal "#{path}?v=#{expected_mtime}", mtime_busted_path(path) | ||
| 9 | end | ||
| 10 | |||
| 11 | test "mtime_busted_path raises clearly for a missing file rather than silently omitting the version" do | ||
| 12 | assert_raises(RuntimeError) { mtime_busted_path("/stylesheets/does_not_exist.css") } | ||
| 13 | end | ||
| 4 | end | 14 | end |
