Permalink
Browse files

ActionCachingTestController rescues from all exceptions. Making sure …

…that all the tests check for valid response. [#4468 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 2e9af36 commit d793d30776737e46ead49d90dcba411c3dfd6edf Neeraj Singh committed with josevalim Apr 25, 2010
Showing with 32 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_controller/caching/actions.rb
  2. +31 −0 actionpack/test/controller/caching_test.rb
@@ -133,7 +133,7 @@ def filter(controller)
body = controller._save_fragment(cache_path.path, @store_options)
end
- body = controller.render_to_string(:text => cache, :layout => true) unless @cache_layout
+ body = controller.render_to_string(:text => body, :layout => true) unless @cache_layout
controller.response_body = body
controller.content_type = Mime[cache_path.extension || :html]
@@ -265,49 +265,57 @@ def teardown
def test_simple_action_cache
get :index
+ assert_response :success
cached_time = content_to_cache
assert_equal cached_time, @response.body
assert fragment_exist?('hostname.com/action_caching_test')
reset!
get :index
+ assert_response :success
assert_equal cached_time, @response.body
end
def test_simple_action_not_cached
get :destroy
+ assert_response :success
cached_time = content_to_cache
assert_equal cached_time, @response.body
assert !fragment_exist?('hostname.com/action_caching_test/destroy')
reset!
get :destroy
+ assert_response :success
assert_not_equal cached_time, @response.body
end
include RackTestUtils
def test_action_cache_with_layout
get :with_layout
+ assert_response :success
cached_time = content_to_cache
assert_not_equal cached_time, @response.body
assert fragment_exist?('hostname.com/action_caching_test/with_layout')
reset!
get :with_layout
+ assert_response :success
assert_not_equal cached_time, @response.body
body = body_to_string(read_fragment('hostname.com/action_caching_test/with_layout'))
assert_equal @response.body, body
end
def test_action_cache_with_layout_and_layout_cache_false
get :layout_false
+ assert_response :success
cached_time = content_to_cache
assert_not_equal cached_time, @response.body
assert fragment_exist?('hostname.com/action_caching_test/layout_false')
reset!
get :layout_false
+ assert_response :success
assert_not_equal cached_time, @response.body
body = body_to_string(read_fragment('hostname.com/action_caching_test/layout_false'))
@@ -317,6 +325,7 @@ def test_action_cache_with_layout_and_layout_cache_false
def test_action_cache_conditional_options
@request.env['HTTP_ACCEPT'] = 'application/json'
get :index
+ assert_response :success
assert !fragment_exist?('hostname.com/action_caching_test')
end
@@ -325,41 +334,50 @@ def test_action_cache_with_store_options
@controller.expects(:read_fragment).with('hostname.com/action_caching_test', :expires_in => 1.hour).once
@controller.expects(:write_fragment).with('hostname.com/action_caching_test', '12345.0', :expires_in => 1.hour).once
get :index
+ assert_response :success
end
def test_action_cache_with_custom_cache_path
get :show
+ assert_response :success
cached_time = content_to_cache
assert_equal cached_time, @response.body
assert fragment_exist?('test.host/custom/show')
reset!
get :show
+ assert_response :success
assert_equal cached_time, @response.body
end
def test_action_cache_with_custom_cache_path_in_block
get :edit
+ assert_response :success
assert fragment_exist?('test.host/edit')
reset!
get :edit, :id => 1
+ assert_response :success
assert fragment_exist?('test.host/1;edit')
end
def test_cache_expiration
get :index
+ assert_response :success
cached_time = content_to_cache
reset!
get :index
+ assert_response :success
assert_equal cached_time, @response.body
reset!
get :expire
+ assert_response :success
reset!
get :index
+ assert_response :success
new_cached_time = content_to_cache
assert_not_equal cached_time, @response.body
reset!
@@ -376,35 +394,41 @@ def test_cache_expiration_isnt_affected_by_request_format
@request.request_uri = "/action_caching_test/expire.xml"
get :expire, :format => :xml
+ assert_response :success
reset!
get :index
+ assert_response :success
new_cached_time = content_to_cache
assert_not_equal cached_time, @response.body
end
def test_cache_is_scoped_by_subdomain
@request.host = 'jamis.hostname.com'
get :index
+ assert_response :success
jamis_cache = content_to_cache
reset!
@request.host = 'david.hostname.com'
get :index
+ assert_response :success
david_cache = content_to_cache
assert_not_equal jamis_cache, @response.body
reset!
@request.host = 'jamis.hostname.com'
get :index
+ assert_response :success
assert_equal jamis_cache, @response.body
reset!
@request.host = 'david.hostname.com'
get :index
+ assert_response :success
assert_equal david_cache, @response.body
end
@@ -433,20 +457,24 @@ def test_xml_version_of_resource_is_treated_as_different_cache
end
get :index, :format => 'xml'
+ assert_response :success
cached_time = content_to_cache
assert_equal cached_time, @response.body
assert fragment_exist?('hostname.com/action_caching_test/index.xml')
reset!
get :index, :format => 'xml'
+ assert_response :success
assert_equal cached_time, @response.body
assert_equal 'application/xml', @response.content_type
reset!
get :expire_xml
+ assert_response :success
reset!
get :index, :format => 'xml'
+ assert_response :success
assert_not_equal cached_time, @response.body
end
end
@@ -455,20 +483,23 @@ def test_correct_content_type_is_returned_for_cache_hit
# run it twice to cache it the first time
get :index, :id => 'content-type', :format => 'xml'
get :index, :id => 'content-type', :format => 'xml'
+ assert_response :success
assert_equal 'application/xml', @response.content_type
end
def test_correct_content_type_is_returned_for_cache_hit_on_action_with_string_key
# run it twice to cache it the first time
get :show, :format => 'xml'
get :show, :format => 'xml'
+ assert_response :success
assert_equal 'application/xml', @response.content_type
end
def test_correct_content_type_is_returned_for_cache_hit_on_action_with_string_key_from_proc
# run it twice to cache it the first time
get :edit, :id => 1, :format => 'xml'
get :edit, :id => 1, :format => 'xml'
+ assert_response :success
assert_equal 'application/xml', @response.content_type
end

0 comments on commit d793d30

Please sign in to comment.