]> source.dussan.org Git - redmine.git/commitdiff
Adds a method to clear the settings cache.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 13 Nov 2011 15:20:31 +0000 (15:20 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 13 Nov 2011 15:20:31 +0000 (15:20 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7804 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/setting.rb
test/unit/setting_test.rb

index 12b186fe84be17a63c10653cbd637157b1a07adf..111193caeaee09f19e6b2db5b02de3bf357766a4 100644 (file)
@@ -151,11 +151,16 @@ class Setting < ActiveRecord::Base
   def self.check_cache
     settings_updated_on = Setting.maximum(:updated_on)
     if settings_updated_on && @cached_cleared_on <= settings_updated_on
-      @cached_settings.clear
-      @cached_cleared_on = Time.now
-      logger.info "Settings cache cleared." if logger
+      clear_cache
     end
   end
+  
+  # Clears the settings cache
+  def self.clear_cache
+    @cached_settings.clear
+    @cached_cleared_on = Time.now
+    logger.info "Settings cache cleared." if logger
+  end
 
 private
   # Returns the Setting instance for the setting named name
index 228cd491e51a60df43e3b4d79a95ae8af562fed3..1187ac9ecd362e687f9269abf0103fe96a18a272 100644 (file)
@@ -42,4 +42,17 @@ class SettingTest < ActiveSupport::TestCase
     assert_equal ['issue_added', 'issue_updated', 'news_added'], Setting.notified_events
     assert_equal ['issue_added', 'issue_updated', 'news_added'], Setting.find_by_name('notified_events').value
   end
+  
+  def test_setting_should_be_reloaded_after_clear_cache
+    Setting.app_title = "My title"
+    assert_equal "My title", Setting.app_title
+    
+    s = Setting.find_by_name("app_title")
+    s.value = 'New title'
+    s.save!
+    assert_equal "My title", Setting.app_title
+    
+    Setting.clear_cache
+    assert_equal "New title", Setting.app_title
+  end
 end