From 7adc3adf51232aa17be417be52149c65b7cadd3b Mon Sep 17 00:00:00 2001
From: Takashi Kato <tohosaku@users.osdn.me>
Date: Sun, 27 Oct 2024 12:43:09 +0000
Subject: [PATCH 1/2] Add asset path to default to support old style theme

---
 config/initializers/30-redmine.rb                   |  5 ++++-
 .../themes/foo_theme/stylesheets/application.css    |  2 ++
 test/integration/lib/redmine/themes_test.rb         | 13 +++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 test/fixtures/themes/foo_theme/stylesheets/application.css

diff --git a/config/initializers/30-redmine.rb b/config/initializers/30-redmine.rb
index 4eceaf06dc..cf13cab204 100644
--- a/config/initializers/30-redmine.rb
+++ b/config/initializers/30-redmine.rb
@@ -24,7 +24,10 @@ Redmine::PluginLoader.load
 
 Rails.application.config.to_prepare do
   default_paths = []
-  Rails.application.config.assets.redmine_default_asset_path = Redmine::AssetPath.new(Rails.public_path, default_paths)
+  default_paths << Rails.root.join("app/assets/javascripts")
+  default_paths << Rails.root.join("app/assets/images")
+  default_paths << Rails.root.join("app/assets/stylesheets")
+  Rails.application.config.assets.redmine_default_asset_path = Redmine::AssetPath.new(Rails.root.join('app/assets'), default_paths)
 
   Redmine::FieldFormat::RecordList.subclasses.each do |klass|
     klass.instance.reset_target_class
diff --git a/test/fixtures/themes/foo_theme/stylesheets/application.css b/test/fixtures/themes/foo_theme/stylesheets/application.css
new file mode 100644
index 0000000000..34a9cae501
--- /dev/null
+++ b/test/fixtures/themes/foo_theme/stylesheets/application.css
@@ -0,0 +1,2 @@
+/* load the default Redmine stylesheet */
+@import url(../../../stylesheets/application.css);
diff --git a/test/integration/lib/redmine/themes_test.rb b/test/integration/lib/redmine/themes_test.rb
index 42cacd172e..7dc6b8df0c 100644
--- a/test/integration/lib/redmine/themes_test.rb
+++ b/test/integration/lib/redmine/themes_test.rb
@@ -109,4 +109,17 @@ class ThemesTest < Redmine::IntegrationTest
     assert_response :success
     assert_select 'body[class~="theme-Foo_bar_baz"]'
   end
+
+  def test_old_theme_compatibility
+    @theme = Redmine::Themes::Theme.new(Rails.root.join('test/fixtures/themes/foo_theme'))
+    Rails.application.config.assets.redmine_extension_paths << @theme.asset_paths
+    Setting.ui_theme = @theme.id
+    Rails.application.assets.load_path.clear_cache
+
+    asset = Rails.application.assets.load_path.find('themes/foo_theme/application.css')
+    get "/assets/#{asset.digested_path.to_s}"
+
+    assert_response :success
+    assert_match %r{url\(\"/assets/application-\w+\.css\"\)}, response.body
+  end
 end
-- 
2.39.2

