diff options
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/render_test.rb | 152 |
1 files changed, 99 insertions, 53 deletions
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 9a94db4b00..041c54c7fd 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -8,14 +8,18 @@ module Fun end end - -# FIXME: crashes Ruby 1.9 class TestController < ActionController::Base layout :determine_layout def hello_world end + def conditional_hello + etag! [:foo, 123] + last_modified! Time.now.utc.beginning_of_day + render :action => 'hello_world' unless performed? + end + def render_hello_world render :template => "test/hello_world" end @@ -408,6 +412,72 @@ class RenderTest < Test::Unit::TestCase assert_equal "Goodbye, Local David", @response.body end + def test_should_render_formatted_template + get :formatted_html_erb + assert_equal 'formatted html erb', @response.body + end + + def test_should_render_formatted_xml_erb_template + get :formatted_xml_erb, :format => :xml + assert_equal '<test>passed formatted xml erb</test>', @response.body + end + + def test_should_render_formatted_html_erb_template + get :formatted_xml_erb + assert_equal '<test>passed formatted html erb</test>', @response.body + end + + def test_should_render_formatted_html_erb_template_with_faulty_accepts_header + @request.env["HTTP_ACCEPT"] = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, appliction/x-shockwave-flash, */*" + get :formatted_xml_erb + assert_equal '<test>passed formatted html erb</test>', @response.body + end + + def test_should_render_html_formatted_partial + get :partial + assert_equal 'partial html', @response.body + end + + def test_should_render_html_partial_with_dot + get :partial_dot_html + assert_equal 'partial html', @response.body + end + + def test_should_render_html_formatted_partial_with_rjs + xhr :get, :partial_as_rjs + assert_equal %(Element.replace("foo", "partial html");), @response.body + end + + def test_should_render_html_formatted_partial_with_rjs_and_js_format + xhr :get, :respond_to_partial_as_rjs + assert_equal %(Element.replace("foo", "partial html");), @response.body + end + + def test_should_render_js_partial + xhr :get, :partial, :format => 'js' + assert_equal 'partial js', @response.body + end + + def test_should_render_with_alternate_default_render + xhr :get, :render_alternate_default + assert_equal %(Element.replace("foo", "partial html");), @response.body + end + + def test_should_render_xml_but_keep_custom_content_type + get :render_xml_with_custom_content_type + assert_equal "application/atomsvc+xml", @response.content_type + end +end + +class EtagRenderTest < Test::Unit::TestCase + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @controller = TestController.new + + @request.host = "www.nextangle.com" + end + def test_render_200_should_set_etag get :render_hello_world_from_variable assert_equal etag_for("hello david"), @response.headers['ETag'] @@ -460,64 +530,40 @@ class RenderTest < Test::Unit::TestCase assert_equal etag_for("<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n"), @response.headers['ETag'] end - def test_should_render_formatted_template - get :formatted_html_erb - assert_equal 'formatted html erb', @response.body - end - - def test_should_render_formatted_xml_erb_template - get :formatted_xml_erb, :format => :xml - assert_equal '<test>passed formatted xml erb</test>', @response.body - end - - def test_should_render_formatted_html_erb_template - get :formatted_xml_erb - assert_equal '<test>passed formatted html erb</test>', @response.body - end - - def test_should_render_formatted_html_erb_template_with_faulty_accepts_header - @request.env["HTTP_ACCEPT"] = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, appliction/x-shockwave-flash, */*" - get :formatted_xml_erb - assert_equal '<test>passed formatted html erb</test>', @response.body - end - - def test_should_render_html_formatted_partial - get :partial - assert_equal 'partial html', @response.body - end - - def test_should_render_html_partial_with_dot - get :partial_dot_html - assert_equal 'partial html', @response.body - end + protected + def etag_for(text) + %("#{Digest::MD5.hexdigest(text)}") + end +end - def test_should_render_html_formatted_partial_with_rjs - xhr :get, :partial_as_rjs - assert_equal %(Element.replace("foo", "partial html");), @response.body - end +class LastModifiedRenderTest < Test::Unit::TestCase + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @controller = TestController.new - def test_should_render_html_formatted_partial_with_rjs_and_js_format - xhr :get, :respond_to_partial_as_rjs - assert_equal %(Element.replace("foo", "partial html");), @response.body + @request.host = "www.nextangle.com" + @last_modified = Time.now.utc.beginning_of_day.httpdate end - def test_should_render_js_partial - xhr :get, :partial, :format => 'js' - assert_equal 'partial js', @response.body + def test_responds_with_last_modified + get :conditional_hello + assert_equal @last_modified, @response.headers['Last-Modified'] end - def test_should_render_with_alternate_default_render - xhr :get, :render_alternate_default - assert_equal %(Element.replace("foo", "partial html");), @response.body + def test_request_not_modified + @request.headers["HTTP_IF_MODIFIED_SINCE"] = @last_modified + get :conditional_hello + assert_equal "304 Not Modified", @response.headers['Status'] + assert @response.body.blank?, @response.body + assert_equal @last_modified, @response.headers['Last-Modified'] end - def test_should_render_xml_but_keep_custom_content_type - get :render_xml_with_custom_content_type - assert_equal "application/atomsvc+xml", @response.content_type + def test_request_modified + @request.headers["HTTP_IF_MODIFIED_SINCE"] = 'Thu, 16 Jul 2008 00:00:00 GMT' + get :conditional_hello + assert_equal "200 OK", @response.headers['Status'] + assert !@response.body.blank? + assert_equal @last_modified, @response.headers['Last-Modified'] end - - protected - def etag_for(text) - %("#{Digest::MD5.hexdigest(text)}") - end end |