A platform for community discussion. Free, open, simple.
FIX: extracted theme JavaScripts for multisite (#6502)
Kyle Zhao0f1afad6dab7
diff --git a/app/jobs/onceoff/rebake_all_html_theme_fields.rb b/app/jobs/onceoff/rebake_all_html_theme_fields.rbnew file mode 100644index 00000000000..afdce8abc11--- /dev/null+++ b/app/jobs/onceoff/rebake_all_html_theme_fields.rb@@ -0,0 +1,11 @@+module Jobs+ class RebakeAllHtmlThemeFields < Jobs::Onceoff+ def execute_onceoff(args)+ ThemeField.where(type_id: ThemeField.types[:html]).find_each do |theme_field|+ theme_field.update(value_baked: nil)+ end++ Theme.clear_cache!+ end+ end+enddiff --git a/app/models/javascript_cache.rb b/app/models/javascript_cache.rbindex e11c40feb29..cb850af6de1 100644--- a/app/models/javascript_cache.rb+++ b/app/models/javascript_cache.rb@@ -7,7 +7,7 @@ class JavascriptCache < ActiveRecord::Basebefore_save :update_digestdef url- "#{GlobalSetting.cdn_url}#{GlobalSetting.relative_url_root}/theme-javascripts/#{digest}.js"+ "#{GlobalSetting.cdn_url}#{GlobalSetting.relative_url_root}/theme-javascripts/#{digest}.js?__ws=#{Discourse.current_hostname}"endprivatediff --git a/spec/jobs/rebake_all_html_theme_fields_spec.rb b/spec/jobs/rebake_all_html_theme_fields_spec.rbnew file mode 100644index 00000000000..91dd4828f76--- /dev/null+++ b/spec/jobs/rebake_all_html_theme_fields_spec.rb@@ -0,0 +1,15 @@+require 'rails_helper'++describe Jobs::RebakeAllHtmlThemeFields do+ let(:theme) { Fabricate(:theme) }+ let(:theme_field) { ThemeField.create!(theme: theme, target_id: 0, name: "header", value: "<script>console.log(123)</script>") }++ it 'extracts inline javascripts' do+ theme_field.update_attributes(value_baked: 'need to be rebaked')++ described_class.new.execute_onceoff({})++ theme_field.reload+ expect(theme_field.value_baked).to include('theme-javascripts')+ end+enddiff --git a/spec/models/javascript_cache_spec.rb b/spec/models/javascript_cache_spec.rbindex 1599fbe92e6..28b06a2ea8c 100644--- a/spec/models/javascript_cache_spec.rb+++ b/spec/models/javascript_cache_spec.rb@@ -29,4 +29,11 @@ RSpec.describe JavascriptCache, type: :model doexpect(javascript_cache.errors.details[:content]).to include(error: :empty)endend++ describe 'url' do+ it 'works with multisite' do+ javascript_cache = JavascriptCache.create!(content: 'console.log("hello");', theme_field: theme_field)+ expect(javascript_cache.url).to include("?__ws=test.localhost")+ end+ endend