Permalink
Browse files

Make perform_caching work again, with the tests passing and backward …

…compatible
  • Loading branch information...
1 parent 005c2ba commit 0ea434e2f4083368fe9657aae9ceb5c484336f14 Santiago Pastorino and Carl Lerche committed with spastorino Apr 15, 2010
View
2 actionpack/lib/action_controller/caching.rb
@@ -52,7 +52,7 @@ def cache_store=(store)
private
def cache_configured?
- config.perform_caching && cache_store
+ perform_caching && cache_store
end
end
View
18 actionpack/lib/action_controller/caching/pages.rb
@@ -44,24 +44,24 @@ module Pages
# For Rails, this directory has already been set to Rails.public_path (which is usually set to <tt>Rails.root + "/public"</tt>). Changing
# this setting can be useful to avoid naming conflicts with files in <tt>public/</tt>, but doing so will likely require configuring your
# web server to look in the new location for cached files.
- @@page_cache_directory = ''
- cattr_accessor :page_cache_directory
+ singleton_class.delegate :page_cache_directory, :page_cache_directory=, :to => :config
+ self.page_cache_directory = ''
##
# :singleton-method:
# Most Rails requests do not have an extension, such as <tt>/weblog/new</tt>. In these cases, the page caching mechanism will add one in
# order to make it easy for the cached files to be picked up properly by the web server. By default, this cache extension is <tt>.html</tt>.
# If you want something else, like <tt>.php</tt> or <tt>.shtml</tt>, just set Base.page_cache_extension. In cases where a request already has an
# extension, such as <tt>.xml</tt> or <tt>.rss</tt>, page caching will not add an extension. This allows it to work well with RESTful apps.
- @@page_cache_extension = '.html'
- cattr_accessor :page_cache_extension
+ singleton_class.delegate :page_cache_extension, :page_cache_extension=, :to => :config
+ self.page_cache_extension = '.html'
end
module ClassMethods
# Expires the page that was cached with the +path+ as a key. Example:
# expire_page "/lists/show"
def expire_page(path)
- return unless config.perform_caching
+ return unless perform_caching
path = page_cache_path(path)
instrument_page_cache :expire_page, path do
@@ -72,7 +72,7 @@ def expire_page(path)
# Manually cache the +content+ in the key determined by +path+. Example:
# cache_page "I'm the cached content", "/lists/show"
def cache_page(content, path)
- return unless config.perform_caching
+ return unless perform_caching
path = page_cache_path(path)
instrument_page_cache :write_page, path do
@@ -92,7 +92,7 @@ def cache_page(content, path)
# # cache the index action except for JSON requests
# caches_page :index, :if => Proc.new { |c| !c.request.format.json? }
def caches_page(*actions)
- return unless config.perform_caching
+ return unless perform_caching
options = actions.extract_options!
after_filter({:only => actions}.merge(options)) { |c| c.cache_page }
end
@@ -116,7 +116,7 @@ def instrument_page_cache(name, path)
# Expires the page that was cached with the +options+ as a key. Example:
# expire_page :controller => "lists", :action => "show"
def expire_page(options = {})
- return unless config.perform_caching
+ return unless self.class.perform_caching
if options.is_a?(Hash)
if options[:action].is_a?(Array)
@@ -135,7 +135,7 @@ def expire_page(options = {})
# If no options are provided, the requested url is used. Example:
# cache_page "I'm the cached content", :controller => "lists", :action => "show"
def cache_page(content = nil, options = nil)
- return unless config.perform_caching && caching_allowed
+ return unless self.class.perform_caching && caching_allowed
path = case options
when Hash
View
1 actionpack/lib/action_controller/deprecated/base.rb
@@ -157,7 +157,6 @@ def verify(*args)
deprecated_config_accessor :page_cache_extension
@josevalim
Ruby on Rails member
josevalim added a line comment Apr 16, 2010

If :page_cache_extension is delegating to config (why?), there is no need to do "deprecated_config_accessor :page_cache_extension"

@spastorino
Ruby on Rails member
spastorino added a line comment Apr 16, 2010

Yes, you're right i've to fix this and i think lot of the deprecations are going to be deleted in favor of delegating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
deprecated_config_accessor :protected_instance_variables
deprecated_config_accessor :relative_url_root, "relative_url_root is ineffective. Please stop using it"
- deprecated_config_accessor :perform_caching
deprecated_config_accessor :stylesheets_dir
delegate :consider_all_requests_local, :consider_all_requests_local=,
View
2 actionpack/lib/action_view/helpers/cache_helper.rb
@@ -39,7 +39,7 @@ def cache(name = {}, options = nil, &block)
private
# TODO: Create an object that has caching read/write on it
def fragment_for(name = {}, options = nil, &block) #:nodoc:
- if controller.config.perform_caching
+ if controller.class.perform_caching
if controller.fragment_exist?(name, options)
controller.read_fragment(name, options)
else
View
20 actionpack/test/controller/caching_test.rb
@@ -53,16 +53,16 @@ class PageCachingTest < ActionController::TestCase
def setup
super
- ActionController::Base.perform_caching = true
-
@request = ActionController::TestRequest.new
@request.host = 'hostname.com'
@request.env.delete('PATH_INFO')
- @response = ActionController::TestResponse.new
@controller = PageCachingTestController.new
+ @controller.perform_caching = true
@controller.cache_store = :file_store, FILE_STORE_PATH
+ @response = ActionController::TestResponse.new
+
@params = {:controller => 'posts', :action => 'index', :only_path => true}
FileUtils.rm_rf(File.dirname(FILE_STORE_PATH))
@@ -71,7 +71,7 @@ def setup
def teardown
FileUtils.rm_rf(File.dirname(FILE_STORE_PATH))
- ActionController::Base.perform_caching = false
+ @controller.perform_caching = false
end
def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_default_route
@@ -538,9 +538,9 @@ def some_action; end;
class FragmentCachingTest < ActionController::TestCase
def setup
super
- ActionController::Base.perform_caching = true
@store = ActiveSupport::Cache::MemoryStore.new
@controller = FragmentCachingTestController.new
+ @controller.perform_caching = true
@controller.cache_store = @store
@params = {:controller => 'posts', :action => 'index'}
@request = ActionController::TestRequest.new
@@ -564,7 +564,7 @@ def test_read_fragment_with_caching_enabled
end
def test_read_fragment_with_caching_disabled
- ActionController::Base.perform_caching = false
+ @controller.perform_caching = false
@store.write('views/name', 'value')
assert_nil @controller.read_fragment('name')
end
@@ -576,7 +576,7 @@ def test_fragment_exist_with_caching_enabled
end
def test_fragment_exist_with_caching_disabled
- ActionController::Base.perform_caching = false
+ @controller.perform_caching = false
@store.write('views/name', 'value')
assert !@controller.fragment_exist?('name')
assert !@controller.fragment_exist?('other_name')
@@ -590,7 +590,7 @@ def test_write_fragment_with_caching_enabled
def test_write_fragment_with_caching_disabled
assert_nil @store.read('views/name')
- ActionController::Base.perform_caching = false
+ @controller.perform_caching = false
assert_equal 'value', @controller.write_fragment('name', 'value')
assert_nil @store.read('views/name')
end
@@ -614,7 +614,7 @@ def test_expire_fragment_with_regexp
end
def test_fragment_for_with_disabled_caching
- ActionController::Base.perform_caching = false
+ @controller.perform_caching = false
@store.write('views/expensive', 'fragment content')
fragment_computed = false
@@ -688,9 +688,9 @@ def rescue_action(e)
class FunctionalFragmentCachingTest < ActionController::TestCase
def setup
super
- ActionController::Base.perform_caching = true
@store = ActiveSupport::Cache::MemoryStore.new
@controller = FunctionalCachingController.new
+ @controller.perform_caching = true
@controller.cache_store = @store
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
View
8 actionpack/test/controller/log_subscriber_test.rb
@@ -143,27 +143,27 @@ def test_send_xfile
end
def test_with_fragment_cache
- ActionController::Base.perform_caching = true
+ @controller.config.perform_caching = true
get :with_fragment_cache
wait
assert_equal 4, logs.size
assert_match /Exist fragment\? views\/foo/, logs[1]
assert_match /Write fragment views\/foo/, logs[2]
ensure
- ActionController::Base.perform_caching = true
+ @controller.config.perform_caching = true
end
def test_with_page_cache
- ActionController::Base.perform_caching = true
+ @controller.config.perform_caching = true
get :with_page_cache
wait
assert_equal 3, logs.size
assert_match /Write page/, logs[1]
assert_match /\/index\.html/, logs[1]
ensure
- ActionController::Base.perform_caching = true
+ @controller.config.perform_caching = true
end
def logs

2 comments on commit 0ea434e

@josevalim
Ruby on Rails member

+1 for delegations instead of deprecations.

@spastorino
Ruby on Rails member

Yeap we talked with Carl and decided that is the best to do

Please sign in to comment.