Cleaning up more render tests

This commit is contained in:
Yehuda Katz + Carl Lerche 2009-05-14 15:30:35 -07:00
parent 49a84ff69c
commit 8fac2c88ca
11 changed files with 122 additions and 33 deletions

@ -1,3 +1,6 @@
require "active_support/core_ext/module/attr_internal"
require "active_support/core_ext/module/delegation"
module AbstractController
autoload :Base, "action_controller/abstract/base"
autoload :Callbacks, "action_controller/abstract/callbacks"

@ -23,6 +23,15 @@ def abstract!
end
alias_method :abstract?, :abstract
def inherited(klass)
::AbstractController::Base.subclasses << klass.to_s
super
end
def subclasses
@subclasses ||= []
end
def internal_methods
controller = self

@ -24,6 +24,7 @@
activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
$:.unshift activesupport_path if File.directory?(activesupport_path)
require 'active_support'
require 'active_support/core_ext/class/attribute_accessors'
require File.join(File.dirname(__FILE__), "action_pack")

@ -9,7 +9,7 @@ module TagHelper
include ERB::Util
BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple checked).to_set
BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map(&:to_sym))
BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map {|attr| attr.to_sym })
# Returns an empty HTML tag of type +name+ which by default is XHTML
# compliant. Set +open+ to true to create an open tag compatible

@ -262,6 +262,7 @@ def layout_test
render :action => "hello_world"
end
# :ported:
def builder_layout_test
render :action => "hello", :layout => "layouts/builder"
end
@ -271,6 +272,7 @@ def builder_partial_test
render :action => "hello_world_container"
end
# :ported:
def partials_list
@test_unchanged = 'hello'
@customers = [ Customer.new("david"), Customer.new("mary") ]
@ -860,6 +862,7 @@ def test_render_xml
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 "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
@ -872,11 +875,13 @@ def test_render_xml_with_default
assert_equal "<p>This is grand!</p>\n", @response.body
end
# :move: test in AV
def test_render_xml_with_partial
get :builder_partial_test
assert_equal "<test>\n <hello/>\n</test>\n", @response.body
end
# :ported:
def test_layout_rendering
get :layout_test
assert_equal "<html>Hello world!</html>", @response.body

@ -131,8 +131,10 @@ class BasicController < ::ApplicationController
# 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 @@ def hello_world_with_layout_nil
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 @@ class TestCustomLayout < SimpleRouteCase
assert_status 200
end
class TestLayout < SimpleRouteCase
testing BasicController
test "builder works with layouts" do
get :with_builder_and_layout
assert_response "<html>\n<p>Omg</p>\n</html>\n"
end
end
end
module RenderActionWithControllerLayout

@ -22,8 +22,6 @@ def layout_false
render :layout => false
end
def builder_override
end

@ -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

@ -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 @@ def in_top_directory_with_slash
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 "<html>\n <p>Hello</p>\n</html>\n"
end
end
class WithLayoutController < ::ApplicationController

@ -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

@ -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