diff options
author | José Valim <jose.valim@gmail.com> | 2011-04-18 08:52:29 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-04-18 08:55:41 +0200 |
commit | 389d15ef139e50696b274f2d61dd309ba2632877 (patch) | |
tree | 333341059cbf9227979873345c0cb09338ec45ca /actionpack/test/controller | |
parent | 7a152ab0127877eea6f2cef8ff6d1975a3fc16d4 (diff) | |
download | rails-389d15ef139e50696b274f2d61dd309ba2632877.tar.gz rails-389d15ef139e50696b274f2d61dd309ba2632877.tar.bz2 rails-389d15ef139e50696b274f2d61dd309ba2632877.zip |
Body... wanna *stream* my body? Body... such a thrill my body!
Added stream as class level method to make it explicit when to stream.
Render also accepts :stream as option.
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/new_base/render_streaming_test.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/actionpack/test/controller/new_base/render_streaming_test.rb b/actionpack/test/controller/new_base/render_streaming_test.rb new file mode 100644 index 0000000000..27ba4b1a29 --- /dev/null +++ b/actionpack/test/controller/new_base/render_streaming_test.rb @@ -0,0 +1,62 @@ +require 'abstract_unit' + +module RenderStreaming + class BasicController < ActionController::Base + self.view_paths = [ActionView::FixtureResolver.new( + "render_streaming/basic/hello_world.html.erb" => "Hello world", + "layouts/application.html.erb" => "<%= yield %>, I'm here!" + )] + + layout "application" + stream :only => :hello_world + + def hello_world + end + + def explicit + render :action => "hello_world", :stream => true + end + + def no_layout + render :action => "hello_world", :stream => true, :layout => false + end + + def explicit_cache + headers["Cache-Control"] = "private" + render :action => "hello_world", :stream => true + end + end + + class StreamingTest < Rack::TestCase + test "rendering with streaming enabled at the class level" do + get "/render_streaming/basic/hello_world" + assert_body "b\r\nHello world\r\nb\r\n, I'm here!\r\n0\r\n\r\n" + assert_streaming! + end + + test "rendering with streaming given to render" do + get "/render_streaming/basic/explicit" + assert_body "b\r\nHello world\r\nb\r\n, I'm here!\r\n0\r\n\r\n" + assert_streaming! + end + + test "rendering with streaming do not override explicit cache control given to render" do + get "/render_streaming/basic/explicit_cache" + assert_body "b\r\nHello world\r\nb\r\n, I'm here!\r\n0\r\n\r\n" + assert_streaming! "private" + end + + test "rendering with streaming no layout" do + get "/render_streaming/basic/no_layout" + assert_body "b\r\nHello world\r\n0\r\n\r\n" + assert_streaming! + end + + def assert_streaming!(cache="no-cache") + assert_status 200 + assert_equal nil, headers["Content-Length"] + assert_equal "chunked", headers["Transfer-Encoding"] + assert_equal cache, headers["Cache-Control"] + end + end if defined?(Fiber) +end |