From 0c3d9bc4c2b329cb754bfed1e465f99d058e1193 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Wed, 29 Apr 2009 16:33:24 -0700 Subject: Ported over render :template tests --- actionpack/test/controller/render_test.rb | 19 +++++++++++++++++++ actionpack/test/new_base/render_template_test.rb | 15 ++++++++++++++- actionpack/test/new_base/test_helper.rb | 5 +++++ 3 files changed, 38 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 9149212a2d..d4a18a673c 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -80,6 +80,7 @@ class TestController < ActionController::Base fresh_when(:last_modified => Time.now.utc.beginning_of_day, :etag => [ :foo, 123 ]) end + # :ported: def render_hello_world render :template => "test/hello_world" end @@ -94,14 +95,17 @@ class TestController < ActionController::Base render :template => "test/hello_world" end + # :ported: compatibility def render_hello_world_with_forward_slash render :template => "/test/hello_world" end + # :ported: def render_template_in_top_directory render :template => 'shared' end + # :deprecated: def render_template_in_top_directory_with_slash render :template => '/shared' end @@ -251,6 +255,10 @@ class TestController < ActionController::Base render :js => "alert('hello')" end + # This test is testing 3 things: + # render :file in AV :ported: + # render :template in AC :ported: + # setting content type def render_xml_hello @name = "David" render :template => "test/hello" @@ -399,6 +407,7 @@ class TestController < ActionController::Base render :layout => true, :inline => "Hello: <%= params[:name] %>" end + # :ported: def render_with_explicit_template render :template => "test/hello_world" end @@ -407,6 +416,7 @@ class TestController < ActionController::Base render "test/hello_world" end + # :ported: def render_with_explicit_template_with_locals render :template => "test/render_file_with_locals", :locals => { :secret => 'area51' } end @@ -443,10 +453,15 @@ class TestController < ActionController::Base render :action => "potential_conflicts" end + # :deprecated: + # Tests being able to pick a .builder template over a .erb + # For instance, being able to have hello.xml.builder and hello.xml.erb + # and select one via "hello.builder" or "hello.erb" def hello_world_from_rxml_using_action render :action => "hello_world_from_rxml.builder" end + # :deprecated: def hello_world_from_rxml_using_template render :template => "test/hello_world_from_rxml.builder" end @@ -798,17 +813,20 @@ class RenderTest < ActionController::TestCase end end + # :ported: compatibility def test_render_with_forward_slash get :render_hello_world_with_forward_slash assert_template "test/hello_world" end + # :ported: def test_render_in_top_directory get :render_template_in_top_directory assert_template "shared" assert_equal "Elastica", @response.body end + # :ported: def test_render_in_top_directory_with_slash get :render_template_in_top_directory_with_slash assert_template "shared" @@ -1259,6 +1277,7 @@ class RenderTest < ActionController::TestCase assert_equal "world", assigns["hello"] end + # :ported: def test_template_with_locals get :render_with_explicit_template_with_locals assert_equal "The secret is area51\n", @response.body diff --git a/actionpack/test/new_base/render_template_test.rb b/actionpack/test/new_base/render_template_test.rb index bc52eb019f..63769df082 100644 --- a/actionpack/test/new_base/render_template_test.rb +++ b/actionpack/test/new_base/render_template_test.rb @@ -5,7 +5,8 @@ module RenderTemplate self.view_paths = [ActionView::Template::FixturePath.new( "test/basic.html.erb" => "Hello from basic.html.erb", - "shared.html.erb" => "Elastica" + "shared.html.erb" => "Elastica", + "locals.html.erb" => "The secret is <%= secret %>" )] def index @@ -19,6 +20,10 @@ module RenderTemplate def in_top_directory_with_slash render :template => '/shared' end + + def with_locals + render :template => "locals", :locals => { :secret => 'area51' } + end end class TestWithoutLayout < SimpleRouteCase @@ -44,6 +49,14 @@ module RenderTemplate assert_body "Elastica" assert_status 200 end + + class TestTemplateRenderWithLocals < SimpleRouteCase + describe "rendering a template with local variables" + + get "/render_template/without_layout/with_locals" + assert_body "The secret is area51" + assert_status 200 + end class WithLayoutController < ::ApplicationController diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb index cc79d6faf7..b40cbb163f 100644 --- a/actionpack/test/new_base/test_helper.rb +++ b/actionpack/test/new_base/test_helper.rb @@ -58,6 +58,11 @@ module ActionController end end + def render_to_body(options = {}) + options = {:template => options} if options.is_a?(String) + super + end + # append_view_path File.join(File.dirname(__FILE__), '..', 'fixtures') CORE_METHODS = self.public_instance_methods -- cgit v1.2.3