aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-04-16 10:50:33 +0200
committerJosé Valim <jose.valim@gmail.com>2011-04-16 10:50:33 +0200
commit29078ff8f1561420a405384772c051dc30bdcbf6 (patch)
tree50858283c5dc58d2060ae9340e33b02b1a4e69fa
parent62668cccb9a288b0cd6f6dd49df71661164be2c4 (diff)
downloadrails-29078ff8f1561420a405384772c051dc30bdcbf6.tar.gz
rails-29078ff8f1561420a405384772c051dc30bdcbf6.tar.bz2
rails-29078ff8f1561420a405384772c051dc30bdcbf6.zip
Basic tests for streaming. Basic tests for provide.
-rw-r--r--actionpack/lib/action_view/flows.rb2
-rw-r--r--actionpack/lib/action_view/renderer/streaming_template_renderer.rb2
-rw-r--r--actionpack/test/template/capture_helper_test.rb11
-rw-r--r--actionpack/test/template/streaming_render_test.rb60
4 files changed, 71 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/flows.rb b/actionpack/lib/action_view/flows.rb
index 1ac62961d1..b81a34002a 100644
--- a/actionpack/lib/action_view/flows.rb
+++ b/actionpack/lib/action_view/flows.rb
@@ -13,7 +13,7 @@ module ActionView
end
def set(key, value)
- @content[key] = value
+ @content[key] = (ActiveSupport::SafeBuffer.new << value)
end
def append(key, value)
diff --git a/actionpack/lib/action_view/renderer/streaming_template_renderer.rb b/actionpack/lib/action_view/renderer/streaming_template_renderer.rb
index a8c6ecbde1..1ea00d15ea 100644
--- a/actionpack/lib/action_view/renderer/streaming_template_renderer.rb
+++ b/actionpack/lib/action_view/renderer/streaming_template_renderer.rb
@@ -20,7 +20,7 @@ module ActionView
# object that responds to each. This object is initialized with a block
# that knows how to render the template.
def render_template(template, layout_name = nil, locals = {}) #:nodoc:
- return [super] unless template.supports_streaming?
+ return [super] unless layout_name && template.supports_streaming?
locals ||= {}
layout = layout_name && find_layout(layout_name, locals.keys)
diff --git a/actionpack/test/template/capture_helper_test.rb b/actionpack/test/template/capture_helper_test.rb
index 3ebcb8165f..c2f0825375 100644
--- a/actionpack/test/template/capture_helper_test.rb
+++ b/actionpack/test/template/capture_helper_test.rb
@@ -45,6 +45,17 @@ class CaptureHelperTest < ActionView::TestCase
assert ! content_for?(:something_else)
end
+ def test_provide
+ assert !content_for?(:title)
+ provide :title, "title"
+ assert content_for?(:title)
+ assert_equal "title", @_view_flow.get(:title)
+ provide :title, "<p>title</p>"
+ assert_equal "&lt;p&gt;title&lt;/p&gt;", @_view_flow.get(:title)
+ provide :title, "<p>title</p>".html_safe
+ assert_equal "<p>title</p>", @_view_flow.get(:title)
+ end
+
def test_with_output_buffer_swaps_the_output_buffer_given_no_argument
assert_nil @av.output_buffer
buffer = @av.with_output_buffer do
diff --git a/actionpack/test/template/streaming_render_test.rb b/actionpack/test/template/streaming_render_test.rb
index d6624149d4..06669bb1ee 100644
--- a/actionpack/test/template/streaming_render_test.rb
+++ b/actionpack/test/template/streaming_render_test.rb
@@ -22,12 +22,68 @@ class FiberedTest < ActiveSupport::TestCase
string
end
- def test_render_template_without_layout
+ def test_streaming_works
+ content = []
+ body = @view.render_body(:template => "test/hello_world.erb", :layout => "layouts/yield")
+
+ body.each do |piece|
+ content << piece
+ end
+
+ assert_equal "<title>", content[0]
+ assert_equal "", content[1]
+ assert_equal "</title>\n", content[2]
+ assert_equal "Hello world!", content[3]
+ assert_equal "\n", content[4]
+ end
+
+ def test_render_file
+ assert_equal "Hello world!", buffered_render(:file => "test/hello_world.erb")
+ end
+
+ def test_render_file_with_locals
+ locals = { :secret => 'in the sauce' }
+ assert_equal "The secret is in the sauce\n", buffered_render(:file => "test/render_file_with_locals.erb", :locals => locals)
+ end
+
+ def test_render_partial
+ assert_equal "only partial", buffered_render(:partial => "test/partial_only")
+ end
+
+ def test_render_inline
+ assert_equal "Hello, World!", buffered_render(:inline => "Hello, World!")
+ end
+
+ def test_render_without_layout
assert_equal "Hello world!", buffered_render(:template => "test/hello_world")
end
- def test_render_template_with_layout
+ def test_render_with_layout
assert_equal %(<title></title>\nHello world!\n),
buffered_render(:template => "test/hello_world.erb", :layout => "layouts/yield")
end
+
+ def test_render_with_layout_which_has_render_inline
+ assert_equal %(welcome\nHello world!\n),
+ buffered_render(:template => "test/hello_world.erb", :layout => "layouts/yield_with_render_inline_inside")
+ end
+
+ def test_render_with_layout_which_renders_another_partial
+ assert_equal %(partial html\nHello world!\n),
+ buffered_render(:template => "test/hello_world.erb", :layout => "layouts/yield_with_render_partial_inside")
+ end
+
+ def test_render_with_nested_layout
+ assert_equal %(<title>title</title>\n\n<div id="column">column</div>\n<div id="content">content</div>\n),
+ buffered_render(:template => "test/nested_layout.erb", :layout => "layouts/yield")
+ end
+
+ def test_render_with_file_in_layout
+ assert_equal %(\n<title>title</title>\n\n),
+ buffered_render(:template => "test/layout_render_file.erb")
+ end
+
+ def test_render_with_handler_without_streaming_support
+ assert_match "<p>This is grand!</p>", buffered_render(:template => "test/hello")
+ end
end if defined?(Fiber) \ No newline at end of file