aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-10-10 12:34:31 +0200
committerJosé Valim <jose.valim@gmail.com>2010-10-10 12:43:26 +0200
commit940b57789fb9166658974c591e68d22ecab29f34 (patch)
treeffaf3b57cc89663f5e48a7fc5567dcb510fa931e /actionpack/test
parentb88f4ca93bcaef9a6bfd21d95acc8f432a3c8e5c (diff)
downloadrails-940b57789fb9166658974c591e68d22ecab29f34.tar.gz
rails-940b57789fb9166658974c591e68d22ecab29f34.tar.bz2
rails-940b57789fb9166658974c591e68d22ecab29f34.zip
Add support to render :once.
This will be used internally by sprockets to ensure requires are executed just once.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/new_base/render_once_test.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/actionpack/test/controller/new_base/render_once_test.rb b/actionpack/test/controller/new_base/render_once_test.rb
new file mode 100644
index 0000000000..12892b7255
--- /dev/null
+++ b/actionpack/test/controller/new_base/render_once_test.rb
@@ -0,0 +1,73 @@
+require 'abstract_unit'
+
+module RenderTemplate
+ class RenderOnceController < ActionController::Base
+ layout false
+
+ RESOLVER = ActionView::FixtureResolver.new(
+ "test/a.html.erb" => "a",
+ "test/b.html.erb" => "<>",
+ "test/c.html.erb" => "c",
+ "test/one.html.erb" => "<%= render :once => 'test/result' %>",
+ "test/two.html.erb" => "<%= render :once => 'test/result' %>",
+ "test/three.html.erb" => "<%= render :once => 'test/result' %>",
+ "test/result.html.erb" => "YES!",
+ "layouts/test.html.erb" => "l<%= yield %>l"
+ )
+
+ self.view_paths = [RESOLVER]
+
+ def multiple
+ render :once => %w(test/a test/b test/c)
+ end
+
+ def once
+ render :once => %w(test/one test/two test/three)
+ end
+
+ def duplicate
+ render :once => %w(test/a test/a test/a)
+ end
+
+ def with_layout
+ render :once => %w(test/a test/b test/c), :layout => "test"
+ end
+ end
+
+ module Tests
+ def test_mutliple_arguments_get_all_rendered
+ get :multiple
+ assert_response "a\n<>\nc"
+ end
+
+ def test_referenced_templates_get_rendered_once
+ get :once
+ assert_response "YES!\n\n"
+ end
+
+ def test_duplicated_templates_get_rendered_once
+ get :duplicate
+ assert_response "a"
+ end
+
+ def test_layout_wraps_all_rendered_templates
+ get :with_layout
+ assert_response "la\n<>\ncl"
+ end
+ end
+
+ class TestWithResolverCache < Rack::TestCase
+ testing RenderTemplate::RenderOnceController
+ include Tests
+ end
+
+ # TODO This still needs to be implemented and supported.
+ # class TestWithoutResolverCache < Rack::TestCase
+ # testing RenderTemplate::RenderOnceController
+ # include Tests
+ #
+ # def setup
+ # RenderTemplate::RenderOnceController::RESOLVER.stubs(:caching?).returns(false)
+ # end
+ # end
+end