aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2013-05-02 18:30:54 +0100
committerLouise Crow <louise.crow@gmail.com>2013-05-02 18:34:11 +0100
commit80ad2d4c31075ffc994e8c48ea25e6e3c486c364 (patch)
tree73069c4d2a07742575a8f32f0122a1fddc7f402b
parent9aac71037381741383190b30a053b67c46ecb407 (diff)
Add a simple hook to allow theme tests to load the theme code in the context of Alaveteli.
-rw-r--r--config/initializers/theme_loader.rb21
1 files changed, 16 insertions, 5 deletions
diff --git a/config/initializers/theme_loader.rb b/config/initializers/theme_loader.rb
index 4c8967c97..1ad2d01f1 100644
--- a/config/initializers/theme_loader.rb
+++ b/config/initializers/theme_loader.rb
@@ -2,12 +2,23 @@
# It is used by our config/routes.rb to decide which route extension files to load.
$alaveteli_route_extensions = []
-if ENV["RAILS_ENV"] != "test" # Don't let the themes interfere with Alaveteli specs
+def require_theme(theme_name)
+ theme_main_include = File.expand_path "../../../vendor/plugins/#{theme_name}/lib/alavetelitheme.rb", __FILE__
+ if File.exists? theme_main_include
+ require theme_main_include
+ end
+end
+
+if Rails.env == "test"
+ # By setting this ALAVETELI_TEST_THEME to a theme name, theme tests can run in the Rails
+ # context with the theme loaded. Otherwise the themes from the config aren't loaded in testing
+ # so they don't interfere with core Alaveteli tests
+ if defined? ALAVETELI_TEST_THEME
+ require_theme(ALAVETELI_TEST_THEME)
+ end
+else
for url in AlaveteliConfiguration::theme_urls.reverse
theme_name = url.sub(/.*\/(.*).git/, "\\1")
- theme_main_include = File.expand_path "../../../vendor/plugins/#{theme_name}/lib/alavetelitheme.rb", __FILE__
- if File.exists? theme_main_include
- require theme_main_include
- end
+ require_theme(theme_name)
end
end