aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/caching_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/controller/caching_test.rb')
-rw-r--r--actionpack/test/controller/caching_test.rb55
1 files changed, 43 insertions, 12 deletions
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index c161bea945..01f3e8f2b6 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -16,6 +16,7 @@ end
class PageCachingTestController < CachingController
caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? }
caches_page :found, :not_found
+ caches_page :about_me
def ok
@@ -47,6 +48,14 @@ class PageCachingTestController < CachingController
def trailing_slash
render :text => "Sneak attack"
end
+
+ def about_me
+ respond_to do |format|
+ format.html {render :text => 'I am html'}
+ format.xml {render :text => 'I am xml'}
+ end
+ end
+
end
class PageCachingTest < ActionController::TestCase
@@ -76,7 +85,7 @@ class PageCachingTest < ActionController::TestCase
def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_default_route
with_routing do |set|
- set.draw do |map|
+ set.draw do
match 'posts.:format', :to => 'posts#index', :as => :formatted_posts
match '/', :to => 'posts#index', :as => :main
end
@@ -111,6 +120,13 @@ class PageCachingTest < ActionController::TestCase
assert File.exist?("#{FILE_STORE_PATH}/page_caching_test/trailing_slash.html")
end
+ def test_should_obey_http_accept_attribute
+ @request.env['HTTP_ACCEPT'] = 'text/xml'
+ get :about_me
+ assert File.exist?("#{FILE_STORE_PATH}/page_caching_test/about_me.xml")
+ assert_equal 'I am xml', @response.body
+ end
+
def test_should_cache_with_trailing_slash_on_url
@controller.class.cache_page 'cached content', '/page_caching_test/trailing_slash/'
assert File.exist?("#{FILE_STORE_PATH}/page_caching_test/trailing_slash.html")
@@ -140,6 +156,17 @@ class PageCachingTest < ActionController::TestCase
assert_page_not_cached :ok
end
+ def test_page_caching_directory_set_as_pathname
+ begin
+ ActionController::Base.page_cache_directory = Pathname.new(FILE_STORE_PATH)
+ get :ok
+ assert_response :ok
+ assert_page_cached :ok
+ ensure
+ ActionController::Base.page_cache_directory = FILE_STORE_PATH
+ end
+ end
+
private
def assert_page_cached(action, message = "#{action} should have been cached")
assert page_cached?(action), message
@@ -185,6 +212,7 @@ class ActionCachingTestController < CachingController
def with_layout
@cache_this = MockTime.now.to_f.to_s
+ @title = nil
render :text => @cache_this, :layout => true
end
@@ -240,7 +268,6 @@ class ActionCachingMockController
end
def request
- mocked_path = @mock_path
Object.new.instance_eval(<<-EVAL)
def path; '#{@mock_path}' end
def format; 'all' end
@@ -399,7 +426,6 @@ class ActionCacheTest < ActionController::TestCase
get :index
assert_response :success
- new_cached_time = content_to_cache
assert_not_equal cached_time, @response.body
end
@@ -452,7 +478,7 @@ class ActionCacheTest < ActionController::TestCase
def test_xml_version_of_resource_is_treated_as_different_cache
with_routing do |set|
- set.draw do |map|
+ set.draw do
match ':controller(/:action(.:format))'
end
@@ -533,6 +559,11 @@ class ActionCacheTest < ActionController::TestCase
assert_response 404
end
+ def test_four_oh_four_renders_content
+ get :four_oh_four
+ assert_equal "404'd!", @response.body
+ end
+
def test_simple_runtime_error_returns_500_for_multiple_requests
get :simple_runtime_error
assert_response 500
@@ -637,7 +668,7 @@ class FragmentCachingTest < ActionController::TestCase
@store.write('views/another_name', 'another_value')
@store.write('views/primalgrasp', 'will not expire ;-)')
- @controller.expire_fragment /name/
+ @controller.expire_fragment(/name/)
assert_nil @store.read('views/name')
assert_nil @store.read('views/another_name')
@@ -727,23 +758,23 @@ CACHED
def test_fragment_caching_in_partials
get :html_fragment_cached_with_partial
assert_response :success
- assert_match /Old fragment caching in a partial/, @response.body
- assert_match "Old fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial')
+ assert_match(/Old fragment caching in a partial/, @response.body)
+ assert_match("Old fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial'))
end
def test_render_inline_before_fragment_caching
get :inline_fragment_cached
assert_response :success
- assert_match /Some inline content/, @response.body
- assert_match /Some cached content/, @response.body
- assert_match "Some cached content", @store.read('views/test.host/functional_caching/inline_fragment_cached')
+ assert_match(/Some inline content/, @response.body)
+ assert_match(/Some cached content/, @response.body)
+ assert_match("Some cached content", @store.read('views/test.host/functional_caching/inline_fragment_cached'))
end
def test_fragment_caching_in_rjs_partials
xhr :get, :js_fragment_cached_with_partial
assert_response :success
- assert_match /Old fragment caching in a partial/, @response.body
- assert_match "Old fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial')
+ assert_match(/Old fragment caching in a partial/, @response.body)
+ assert_match("Old fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial'))
end
def test_html_formatted_fragment_caching