Skip to content

A platform for community discussion. Free, open, simple.

DEV: Update qunit site setting loading (#40650)

David Taylorc5b2ab7262e0
diff --git a/app/controllers/bootstrap_controller.rb b/app/controllers/bootstrap_controller.rb
deleted file mode 100644
index 34054332bf9..00000000000
--- a/app/controllers/bootstrap_controller.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class BootstrapController < ApplicationController
- skip_before_action :redirect_to_login_if_required, :check_xhr
- protect_from_forgery except: :site_settings_for_tests
-
- def site_settings_for_tests
- site_settings_json = SiteSetting.client_settings_json_uncached(return_defaults: true)
- theme_site_settings_json = SiteSetting.theme_site_settings_json_uncached(nil)
-
- render plain: <<~JS, content_type: "application/javascript"
- window.CLIENT_SITE_SETTINGS_WITH_DEFAULTS = {
- ...#{site_settings_json},
- ...#{theme_site_settings_json}
- };
- JS
- end
-end
diff --git a/app/helpers/qunit_helper.rb b/app/helpers/qunit_helper.rb
index 5171ed55712..e94f1d74b81 100644
--- a/app/helpers/qunit_helper.rb
+++ b/app/helpers/qunit_helper.rb
@@ -17,6 +17,7 @@ module QunitHelper
def fake_preload_data
preloaded = {}
preloaded.merge!(theme_settings_preload_data)
+ preloaded.merge!(site_settings_preload_data)
return "" if preloaded.empty?
tag.div("", id: "data-preloaded", data: { preloaded: preloaded.to_json })
@@ -31,4 +32,11 @@ module QunitHelper
activated_themes = { theme.id => { name: theme.name, settings: theme.cached_default_settings } }
{ "activatedThemes" => activated_themes.to_json }
end
+
+ def site_settings_preload_data
+ {
+ "siteSettings" => SiteSetting.client_settings_json_uncached(return_defaults: true),
+ "themeSiteSettingOverrides" => SiteSetting.theme_site_settings_json_uncached(nil),
+ }
+ end
end
diff --git a/app/views/qunit/qunit.html.erb b/app/views/qunit/qunit.html.erb
index ca1b8065b2e..8b0b49e2a25 100644
--- a/app/views/qunit/qunit.html.erb
+++ b/app/views/qunit/qunit.html.erb
@@ -11,7 +11,6 @@
<%= preload_script_url ExtraLocalesController.url("mf"), type_module: true %>
<%= preload_script_url ExtraLocalesController.url("admin"), type_module: true %>
<%= preload_script_url ExtraLocalesController.url("wizard"), type_module: true %>
- <%= preload_script_url "/bootstrap/site-settings-for-tests.js", type_module: true %>
<%= theme_translations_lookup %>
<script nonce="<%= csp_nonce_placeholder %>">
diff --git a/config/routes.rb b/config/routes.rb
index 575cac3c782..757471cf94a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -24,10 +24,6 @@ Discourse::Application.routes.draw do
match "/404", to: "exceptions#not_found", via: %i[get post]
get "/404-body" => "exceptions#not_found_body"
- if Rails.env.local?
- get "/bootstrap/site-settings-for-tests.js" => "bootstrap#site_settings_for_tests"
- end
-
# This is not a valid production route and is causing routing errors to be raised in
# the test env adding noise to the logs. Just handle it here so we eliminate the noise.
get "/favicon.ico", to: proc { [200, {}, [""]] } if Rails.env.test?
diff --git a/frontend/discourse/tests/helpers/site-settings.js b/frontend/discourse/tests/helpers/site-settings.js
index 527063b6c97..fbfcfdfdd27 100644
--- a/frontend/discourse/tests/helpers/site-settings.js
+++ b/frontend/discourse/tests/helpers/site-settings.js
@@ -1,3 +1,4 @@
+import PreloadStore from "discourse/lib/preload-store";
import { createSiteSettingsFromPreloaded } from "discourse/services/site-settings";
const CLIENT_SETTING_TEST_OVERRIDES = {
@@ -13,9 +14,9 @@ const CLIENT_SETTING_TEST_OVERRIDES = {
anon_polling_interval: 30000,
};
-// window.CLIENT_SITE_SETTINGS_WITH_DEFAULTS is injected by `/bootstrap/site-settings-for-tests.js`
const ORIGINAL_CLIENT_SITE_SETTINGS = {
- ...window.CLIENT_SITE_SETTINGS_WITH_DEFAULTS,
+ ...PreloadStore.get("siteSettings"),
+ ...PreloadStore.get("themeSiteSettingOverrides"),
...CLIENT_SETTING_TEST_OVERRIDES,
};