aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-01-12 01:19:46 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-01-12 01:19:46 +0000
commiteff27ab11962aa90885653438d0d04d3136fd846 (patch)
tree511e36e849b11e41b0b5436c363426fc2e4fc073
parent3dd6027f708a472064e73a50f4afb433f338bf09 (diff)
downloadrails-eff27ab11962aa90885653438d0d04d3136fd846.tar.gz
rails-eff27ab11962aa90885653438d0d04d3136fd846.tar.bz2
rails-eff27ab11962aa90885653438d0d04d3136fd846.zip
Fix a few caching errors, expose a case thats still not working (ref #107330 [catfish]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8630 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/lib/action_view/helpers/cache_helper.rb4
-rw-r--r--actionpack/test/controller/caching_test.rb68
-rw-r--r--actionpack/test/fixtures/functional_caching/_partial.erb3
-rw-r--r--actionpack/test/fixtures/functional_caching/fragment_cached.html.erb2
-rw-r--r--actionpack/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb1
-rw-r--r--actionpack/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs1
6 files changed, 76 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/cache_helper.rb b/actionpack/lib/action_view/helpers/cache_helper.rb
index 059f2edf0f..ea505adfa7 100644
--- a/actionpack/lib/action_view/helpers/cache_helper.rb
+++ b/actionpack/lib/action_view/helpers/cache_helper.rb
@@ -32,8 +32,8 @@ module ActionView
# <i>Topics listed alphabetically</i>
# <% end %>
def cache(name = {}, options = nil, &block)
- template_extension = find_template_extension_for(first_render)[/\.(\w+)$/, 1].to_sym
- handler = Base.handler_for_extension(template_extension)
+ template_extension = find_template_extension_for(first_render)[/\.?(\w+)$/, 1].to_sym
+ handler = Base.handler_class_for_extension(template_extension)
handler.new(@controller).cache_fragment(block, name, options)
end
end
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index 9d4dc4d01c..7bd64e2870 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -367,7 +367,7 @@ class FragmentCachingTest < Test::Unit::TestCase
@controller.send(:initialize_current_url)
end
- def test_fragement_cache_key
+ def test_fragment_cache_key
assert_equal 'views/what a key', @controller.fragment_cache_key('what a key')
assert_equal( "views/test.host/fragment_caching_test/some_action",
@controller.fragment_cache_key(:controller => 'fragment_caching_test',:action => 'some_action'))
@@ -479,3 +479,69 @@ class FragmentCachingTest < Test::Unit::TestCase
end
end
end
+
+
+class FunctionalCachingController < ActionController::Base
+ def fragment_cached
+ end
+
+ def html_fragment_cached_with_partial
+ respond_to do |format|
+ format.html
+ end
+ end
+
+ def js_fragment_cached_with_partial
+ respond_to do |format|
+ format.js
+ end
+ end
+
+
+ def rescue_action(e)
+ raise e
+ end
+end
+
+FunctionalCachingController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
+
+class FunctionalFragmentCachingTest < Test::Unit::TestCase
+ def setup
+ ActionController::Base.perform_caching = true
+ @store = ActiveSupport::Cache::MemoryStore.new
+ ActionController::Base.cache_store = @store
+ @controller = FunctionalCachingController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ end
+ def test_fragment_caching
+ get :fragment_cached
+ assert_response :success
+ expected_body = <<-CACHED
+Hello
+This bit's fragment cached
+CACHED
+ assert_equal expected_body, @response.body
+
+ assert_equal "This bit's fragment cached", @store.read('views/test.host/functional_caching/fragment_cached')
+ end
+
+ def test_fragment_caching_in_partials
+ get :html_fragment_cached_with_partial
+ assert_response :success
+ assert_match /Fragment caching in a partial/, @response.body
+ assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial')
+ end
+
+ def test_fragment_caching_in_rjs_partials
+ xhr :get, :js_fragment_cached_with_partial
+ assert_response :success
+ assert_match /Fragment caching in a partial/, @response.body
+ assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial')
+ end
+end
+
+
+
+
+
diff --git a/actionpack/test/fixtures/functional_caching/_partial.erb b/actionpack/test/fixtures/functional_caching/_partial.erb
new file mode 100644
index 0000000000..d0e4f72b95
--- /dev/null
+++ b/actionpack/test/fixtures/functional_caching/_partial.erb
@@ -0,0 +1,3 @@
+<% cache do %>
+Fragment caching in a partial
+<% end %> \ No newline at end of file
diff --git a/actionpack/test/fixtures/functional_caching/fragment_cached.html.erb b/actionpack/test/fixtures/functional_caching/fragment_cached.html.erb
new file mode 100644
index 0000000000..268a298a42
--- /dev/null
+++ b/actionpack/test/fixtures/functional_caching/fragment_cached.html.erb
@@ -0,0 +1,2 @@
+Hello
+<% cache do %>This bit's fragment cached<% end %>
diff --git a/actionpack/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb b/actionpack/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb
new file mode 100644
index 0000000000..a9462d3499
--- /dev/null
+++ b/actionpack/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb
@@ -0,0 +1 @@
+<%= render :partial => 'partial' %> \ No newline at end of file
diff --git a/actionpack/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs b/actionpack/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs
new file mode 100644
index 0000000000..248842c9da
--- /dev/null
+++ b/actionpack/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs
@@ -0,0 +1 @@
+page.replace_html 'notices', :partial => 'partial' \ No newline at end of file