From 8fac2c88cae0f2fd42fad3c2c2c6c860df14d629 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 14 May 2009 15:30:35 -0700 Subject: Cleaning up more render tests --- actionpack/test/controller/render_test.rb | 5 ++ actionpack/test/new_base/render_action_test.rb | 17 +++++- actionpack/test/new_base/render_layout_test.rb | 2 - actionpack/test/new_base/render_partial_test.rb | 27 +++++++++ actionpack/test/new_base/render_template_test.rb | 76 +++++++++++++++--------- actionpack/test/new_base/render_xml_test.rb | 11 ++++ actionpack/test/new_base/test_helper.rb | 2 +- 7 files changed, 108 insertions(+), 32 deletions(-) create mode 100644 actionpack/test/new_base/render_partial_test.rb create mode 100644 actionpack/test/new_base/render_xml_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 469e8601d0..a750f018b8 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -262,6 +262,7 @@ class TestController < ActionController::Base render :action => "hello_world" end + # :ported: def builder_layout_test render :action => "hello", :layout => "layouts/builder" end @@ -271,6 +272,7 @@ class TestController < ActionController::Base render :action => "hello_world_container" end + # :ported: def partials_list @test_unchanged = 'hello' @customers = [ Customer.new("david"), Customer.new("mary") ] @@ -860,6 +862,7 @@ class RenderTest < ActionController::TestCase assert_equal "application/xml", @response.content_type end + # :ported: def test_render_xml_as_string_template get :render_xml_hello_as_string_template assert_equal "\n

Hello David

\n

This is grand!

\n\n", @response.body @@ -872,11 +875,13 @@ class RenderTest < ActionController::TestCase assert_equal "

This is grand!

\n", @response.body end + # :move: test in AV def test_render_xml_with_partial get :builder_partial_test assert_equal "\n \n\n", @response.body end + # :ported: def test_layout_rendering get :layout_test assert_equal "Hello world!", @response.body diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb index 348d70381b..f25faee433 100644 --- a/actionpack/test/new_base/render_action_test.rb +++ b/actionpack/test/new_base/render_action_test.rb @@ -131,8 +131,10 @@ module RenderActionWithApplicationLayout # Set the view path to an application view structure with layouts self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new( "render_action_with_application_layout/basic/hello_world.html.erb" => "Hello World!", + "render_action_with_application_layout/basic/hello.html.builder" => "xml.p 'Omg'", "layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI", - "layouts/greetings.html.erb" => "Greetings <%= yield %> Bai" + "layouts/greetings.html.erb" => "Greetings <%= yield %> Bai", + "layouts/builder.html.builder" => "xml.html do\n xml << yield\nend" )] def hello_world @@ -154,6 +156,10 @@ module RenderActionWithApplicationLayout def hello_world_with_custom_layout render :action => "hello_world", :layout => "greetings" end + + def with_builder_and_layout + render :action => "hello", :layout => "builder" + end end class TestDefaultLayout < SimpleRouteCase @@ -199,6 +205,15 @@ module RenderActionWithApplicationLayout assert_status 200 end + class TestLayout < SimpleRouteCase + testing BasicController + + test "builder works with layouts" do + get :with_builder_and_layout + assert_response "\n

Omg

\n\n" + end + end + end module RenderActionWithControllerLayout diff --git a/actionpack/test/new_base/render_layout_test.rb b/actionpack/test/new_base/render_layout_test.rb index 7f627f86ec..dc858b4f5c 100644 --- a/actionpack/test/new_base/render_layout_test.rb +++ b/actionpack/test/new_base/render_layout_test.rb @@ -22,8 +22,6 @@ module ControllerLayouts render :layout => false end - - def builder_override end diff --git a/actionpack/test/new_base/render_partial_test.rb b/actionpack/test/new_base/render_partial_test.rb new file mode 100644 index 0000000000..3a300afe5c --- /dev/null +++ b/actionpack/test/new_base/render_partial_test.rb @@ -0,0 +1,27 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") + +module RenderPartial + + class BasicController < ActionController::Base + + self.view_paths = [ActionView::Template::FixturePath.new( + "render_partial/basic/_basic.html.erb" => "OMG!", + "render_partial/basic/basic.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'basic' %><%= @test_unchanged %>" + )] + + def changing + @test_unchanged = 'hello' + render :action => "basic" + end + end + + class TestPartial < SimpleRouteCase + testing BasicController + + test "rendering a partial in ActionView doesn't pull the ivars again from the controller" do + get :changing + assert_response("goodbyeOMG!goodbye") + end + end + +end \ No newline at end of file diff --git a/actionpack/test/new_base/render_template_test.rb b/actionpack/test/new_base/render_template_test.rb index c09eeb1926..6c50ae4203 100644 --- a/actionpack/test/new_base/render_template_test.rb +++ b/actionpack/test/new_base/render_template_test.rb @@ -4,14 +4,19 @@ module RenderTemplate class WithoutLayoutController < ActionController::Base self.view_paths = [ActionView::Template::FixturePath.new( - "test/basic.html.erb" => "Hello from basic.html.erb", - "shared.html.erb" => "Elastica", - "locals.html.erb" => "The secret is <%= secret %>" + "test/basic.html.erb" => "Hello from basic.html.erb", + "shared.html.erb" => "Elastica", + "locals.html.erb" => "The secret is <%= secret %>", + "xml_template.xml.builder" => "xml.html do\n xml.p 'Hello'\nend" )] def index render :template => "test/basic" end + + def index_without_key + render "test/basic" + end def in_top_directory render :template => 'shared' @@ -21,41 +26,56 @@ module RenderTemplate render :template => '/shared' end + def in_top_directory_with_slash_without_key + render '/shared' + end + def with_locals render :template => "locals", :locals => { :secret => 'area51' } end + + def builder_template + render :template => "xml_template" + end end class TestWithoutLayout < SimpleRouteCase - describe "rendering a normal template with full path without layout" + testing RenderTemplate::WithoutLayoutController - get "/render_template/without_layout" - assert_body "Hello from basic.html.erb" - assert_status 200 - end - - class TestTemplateRenderInTopDirectory < SimpleRouteCase - describe "rendering a template not in a subdirectory" + test "rendering a normal template with full path without layout" do + get :index + assert_response "Hello from basic.html.erb" + end - get "/render_template/without_layout/in_top_directory" - assert_body "Elastica" - assert_status 200 - end - - class TestTemplateRenderInTopDirectoryWithSlash < SimpleRouteCase - describe "rendering a template not in a subdirectory with a leading slash" + test "rendering a normal template with full path without layout without key" do + get :index_without_key + assert_response "Hello from basic.html.erb" + end - get "/render_template/without_layout/in_top_directory_with_slash" - assert_body "Elastica" - assert_status 200 - end - - class TestTemplateRenderWithLocals < SimpleRouteCase - describe "rendering a template with local variables" + test "rendering a template not in a subdirectory" do + get :in_top_directory + assert_response "Elastica" + end - get "/render_template/without_layout/with_locals" - assert_body "The secret is area51" - assert_status 200 + test "rendering a template not in a subdirectory with a leading slash" do + get :in_top_directory_with_slash + assert_response "Elastica" + end + + test "rendering a template not in a subdirectory with a leading slash without key" do + get :in_top_directory_with_slash_without_key + assert_response "Elastica" + end + + test "rendering a template with local variables" do + get :with_locals + assert_response "The secret is area51" + end + + test "rendering a builder template" do + get :builder_template + assert_response "\n

Hello

\n\n" + end end class WithLayoutController < ::ApplicationController diff --git a/actionpack/test/new_base/render_xml_test.rb b/actionpack/test/new_base/render_xml_test.rb new file mode 100644 index 0000000000..e6c40b1533 --- /dev/null +++ b/actionpack/test/new_base/render_xml_test.rb @@ -0,0 +1,11 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") + +module RenderXml + + # This has no layout and it works + class BasicController < ActionController::Base + self.view_paths = [ActionView::Template::FixturePath.new( + "render_xml/basic/with_render_erb" => "Hello world!" + )] + end +end \ No newline at end of file diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb index a7302af060..ec7dbffaae 100644 --- a/actionpack/test/new_base/test_helper.rb +++ b/actionpack/test/new_base/test_helper.rb @@ -46,7 +46,7 @@ class Rack::TestCase < ActiveSupport::TestCase ActionController::Routing.use_controllers!(controllers) # Move into a bootloader - AbstractController::Base.subclasses.each do |klass| + ActionController::Base.subclasses.each do |klass| klass = klass.constantize next unless klass < AbstractController::Layouts klass.class_eval do -- cgit v1.2.3