aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-05-01 13:00:51 +0200
committerJosé Valim <jose.valim@gmail.com>2011-05-01 13:40:14 +0200
commit6960a230fa2c2b7cf59266fc903ce0c11e887a9f (patch)
treea232333a82038f5f4df2a61d547f3c0065cff97c /actionpack
parentb73576138529b1344a38f4e4b16c642f3510d514 (diff)
downloadrails-6960a230fa2c2b7cf59266fc903ce0c11e887a9f.tar.gz
rails-6960a230fa2c2b7cf59266fc903ce0c11e887a9f.tar.bz2
rails-6960a230fa2c2b7cf59266fc903ce0c11e887a9f.zip
Add a test for rendering from the controller context.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/test/controller/new_base/render_context_test.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/actionpack/test/controller/new_base/render_context_test.rb b/actionpack/test/controller/new_base/render_context_test.rb
new file mode 100644
index 0000000000..3174bf42ab
--- /dev/null
+++ b/actionpack/test/controller/new_base/render_context_test.rb
@@ -0,0 +1,54 @@
+require 'abstract_unit'
+
+module RenderContext
+ class BasicController < ActionController::Base
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "render_context/basic/hello_world.html.erb" => "<%= @value %> from <%= self.__controller_method__ %>",
+ "layouts/basic.html.erb" => "?<%= yield %>?"
+ )]
+
+ # Include ViewContext
+ include ActionView::Context
+
+ # And initialize the required variables
+ before_filter do
+ @output_buffer = nil
+ @virtual_path = nil
+ @view_flow = ActionView::OutputFlow.new
+ end
+
+ def hello_world
+ @value = "Hello"
+ render :action => "hello_world", :layout => false
+ end
+
+ def with_layout
+ @value = "Hello"
+ render :action => "hello_world", :layout => "basic"
+ end
+
+ protected
+
+ def view_context
+ self
+ end
+
+ def __controller_method__
+ "controller context!"
+ end
+ end
+
+ class RenderContextTest < Rack::TestCase
+ test "rendering using the controller as context" do
+ get "/render_context/basic/hello_world"
+ assert_body "Hello from controller context!"
+ assert_status 200
+ end
+
+ test "rendering using the controller as context with layout" do
+ get "/render_context/basic/with_layout"
+ assert_body "?Hello from controller context!?"
+ assert_status 200
+ end
+ end
+end