Skip to content
Browse files

Expire cache on theme change from admin/settings

Force cache expiration when changing the theme from the Admin::Settings
controller as is done when changing the theme from the Admin::Themes
controller so that the behavior after a change of theme is consistent,
regardless of where the change is made.
  • Loading branch information...
1 parent b68e9b2 commit 9a7251f4b1e8e7147935b1cad8d6f126196bf051 @davec davec committed with emk Mar 2, 2009
Showing with 29 additions and 0 deletions.
  1. +6 −0 app/controllers/admin/settings_controller.rb
  2. +5 −0 test/actor.rb
  3. +18 −0 test/integration/caching_test.rb
View
6 app/controllers/admin/settings_controller.rb
@@ -3,7 +3,13 @@ class Admin::SettingsController < Admin::BaseController
clear_empty_templates_for :site, :tag_layout, :only => :update
def update
+ old_theme_path = site.current_theme_path
if site.update_attributes params[:site]
+ unless old_theme_path == site.current_theme_path
+ site.change_theme_to site.current_theme_path
+ flash[:notice] = "Your theme has been changed to '#{site.current_theme_path}'"
+ site.expire_cached_pages self, "Expired all referenced pages"
+ end
redirect_to :action => 'index'
else
render :action => 'index'
View
5 test/actor.rb
@@ -72,6 +72,11 @@ def create(params)
assert_redirected_to "/admin/articles/#{assigns(:article).id}/edit"
end
+ def update_site_settings(options = {})
+ post "/admin/settings/update", :site => options
+ assert_redirected_to "/admin/settings"
+ end
+
private
def manage_comment(action, comment)
post "/admin/articles/#{comment.article_id}/comments/#{comment.id}/#{action}", :comment => comment.id
View
18 test/integration/caching_test.rb
@@ -425,6 +425,24 @@ def test_should_not_cache_redirected_route
end
end
+ def test_should_expire_cache_when_site_theme_changed
+ visit_sections_and_feeds_with visit_with_session
+ assert_expires_pages section_url_for(:home), section_url_for(:about), feed_url_for(:home), feed_url_for(:about) do
+ login_as :quentin do |writer|
+ writer.update_site_settings :current_theme_path => 'encytemedia'
+ end
+ end
+ end
+
+ def test_should_not_expire_cache_when_site_them_is_not_changed
+ visit_sections_and_feeds_with visit_with_session
+ assert_caches_pages section_url_for(:home), section_url_for(:about), feed_url_for(:home), feed_url_for(:about) do
+ login_as :quentin do |writer|
+ writer.update_site_settings :title => 'Foo'
+ end
+ end
+ end
+
protected
include Mephisto::Caching::ReferencedCachingTestHelper

0 comments on commit 9a7251f

Please sign in to comment.
Something went wrong with that request. Please try again.