2009-03-19 16:35:39 -04:00
|
|
|
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
module RenderAction
|
2009-03-19 18:45:48 -04:00
|
|
|
# This has no layout and it works
|
2009-05-01 20:27:44 -04:00
|
|
|
class BasicController < ActionController::Base
|
2009-06-17 18:32:55 -04:00
|
|
|
self.view_paths = [ActionView::FixtureResolver.new(
|
2009-03-23 15:07:34 -04:00
|
|
|
"render_action/basic/hello_world.html.erb" => "Hello world!"
|
2009-03-20 21:38:03 -04:00
|
|
|
)]
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world
|
2009-03-19 16:35:39 -04:00
|
|
|
render :action => "hello_world"
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_as_string
|
2009-03-19 16:35:39 -04:00
|
|
|
render "hello_world"
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_as_string_with_options
|
2009-03-19 16:35:39 -04:00
|
|
|
render "hello_world", :status => 404
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_as_symbol
|
2009-03-19 16:35:39 -04:00
|
|
|
render :hello_world
|
|
|
|
end
|
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_symbol
|
2009-03-19 16:35:39 -04:00
|
|
|
render :action => :hello_world
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_layout
|
|
|
|
render :action => "hello_world", :layout => true
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_layout_false
|
|
|
|
render :action => "hello_world", :layout => false
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_layout_nil
|
|
|
|
render :action => "hello_world", :layout => nil
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_custom_layout
|
|
|
|
render :action => "hello_world", :layout => "greetings"
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-19 16:35:39 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
|
|
|
class RenderActionTest < SimpleRouteCase
|
|
|
|
test "rendering an action using :action => <String>" do
|
|
|
|
get "/render_action/basic/hello_world"
|
|
|
|
|
|
|
|
assert_body "Hello world!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering an action using '<action>'" do
|
|
|
|
get "/render_action/basic/hello_world_as_string"
|
|
|
|
|
|
|
|
assert_body "Hello world!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering an action using '<action>' and options" do
|
|
|
|
get "/render_action/basic/hello_world_as_string_with_options"
|
|
|
|
|
|
|
|
assert_body "Hello world!"
|
|
|
|
assert_status 404
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering an action using :action" do
|
|
|
|
get "/render_action/basic/hello_world_as_symbol"
|
|
|
|
|
|
|
|
assert_body "Hello world!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering an action using :action => :hello_world" do
|
|
|
|
get "/render_action/basic/hello_world_with_symbol"
|
|
|
|
|
|
|
|
assert_body "Hello world!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-03-19 16:35:39 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
|
|
|
class RenderLayoutTest < SimpleRouteCase
|
|
|
|
describe "Both <controller_path>.html.erb and application.html.erb are missing"
|
|
|
|
|
|
|
|
test "rendering with layout => true" do
|
|
|
|
assert_raise(ArgumentError, /no default layout for RenderAction::BasicController in/) do
|
2009-05-17 13:24:42 -04:00
|
|
|
get "/render_action/basic/hello_world_with_layout", {}, "action_dispatch.show_exceptions" => false
|
2009-04-07 20:57:20 -04:00
|
|
|
end
|
2009-03-19 19:11:20 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
|
|
|
test "rendering with layout => false" do
|
|
|
|
get "/render_action/basic/hello_world_with_layout_false"
|
|
|
|
|
|
|
|
assert_body "Hello world!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering with layout => :nil" do
|
|
|
|
get "/render_action/basic/hello_world_with_layout_nil"
|
|
|
|
|
|
|
|
assert_body "Hello world!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering with layout => 'greetings'" do
|
2009-05-16 14:15:26 -04:00
|
|
|
assert_raise(ActionView::MissingTemplate) do
|
2009-05-17 13:24:42 -04:00
|
|
|
get "/render_action/basic/hello_world_with_custom_layout", {}, "action_dispatch.show_exceptions" => false
|
2009-05-16 14:15:26 -04:00
|
|
|
end
|
2009-03-19 19:11:20 -04:00
|
|
|
end
|
|
|
|
end
|
2009-03-23 15:07:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
module RenderActionWithApplicationLayout
|
|
|
|
# # ==== Render actions with layouts ====
|
2009-04-07 20:57:20 -04:00
|
|
|
class BasicController < ::ApplicationController
|
2009-03-23 15:07:34 -04:00
|
|
|
# Set the view path to an application view structure with layouts
|
2009-06-17 18:32:55 -04:00
|
|
|
self.view_paths = self.view_paths = [ActionView::FixtureResolver.new(
|
2009-03-23 15:07:34 -04:00
|
|
|
"render_action_with_application_layout/basic/hello_world.html.erb" => "Hello World!",
|
2009-05-14 18:30:35 -04:00
|
|
|
"render_action_with_application_layout/basic/hello.html.builder" => "xml.p 'Omg'",
|
2009-04-07 20:57:20 -04:00
|
|
|
"layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
|
2009-05-14 18:30:35 -04:00
|
|
|
"layouts/greetings.html.erb" => "Greetings <%= yield %> Bai",
|
|
|
|
"layouts/builder.html.builder" => "xml.html do\n xml << yield\nend"
|
2009-03-23 15:07:34 -04:00
|
|
|
)]
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-19 18:45:48 -04:00
|
|
|
def hello_world
|
|
|
|
render :action => "hello_world"
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_layout
|
|
|
|
render :action => "hello_world", :layout => true
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_layout_false
|
|
|
|
render :action => "hello_world", :layout => false
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_layout_nil
|
|
|
|
render :action => "hello_world", :layout => nil
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_custom_layout
|
|
|
|
render :action => "hello_world", :layout => "greetings"
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-05-14 18:30:35 -04:00
|
|
|
def with_builder_and_layout
|
|
|
|
render :action => "hello", :layout => "builder"
|
|
|
|
end
|
2009-03-19 18:45:48 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
|
|
|
class LayoutTest < SimpleRouteCase
|
|
|
|
describe "Only application.html.erb is present and <controller_path>.html.erb is missing"
|
|
|
|
|
|
|
|
test "rendering implicit application.html.erb as layout" do
|
|
|
|
get "/render_action_with_application_layout/basic/hello_world"
|
|
|
|
|
|
|
|
assert_body "OHAI Hello World! KTHXBAI"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering with layout => true" do
|
|
|
|
get "/render_action_with_application_layout/basic/hello_world_with_layout"
|
|
|
|
|
|
|
|
assert_body "OHAI Hello World! KTHXBAI"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering with layout => false" do
|
|
|
|
get "/render_action_with_application_layout/basic/hello_world_with_layout_false"
|
|
|
|
|
|
|
|
assert_body "Hello World!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering with layout => :nil" do
|
|
|
|
get "/render_action_with_application_layout/basic/hello_world_with_layout_nil"
|
|
|
|
|
|
|
|
assert_body "Hello World!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering with layout => 'greetings'" do
|
|
|
|
get "/render_action_with_application_layout/basic/hello_world_with_custom_layout"
|
|
|
|
|
|
|
|
assert_body "Greetings Hello World! Bai"
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-03-23 15:07:34 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-05-14 18:30:35 -04:00
|
|
|
class TestLayout < SimpleRouteCase
|
|
|
|
testing BasicController
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-05-14 18:30:35 -04:00
|
|
|
test "builder works with layouts" do
|
|
|
|
get :with_builder_and_layout
|
|
|
|
assert_response "<html>\n<p>Omg</p>\n</html>\n"
|
|
|
|
end
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
module RenderActionWithControllerLayout
|
2009-05-01 20:27:44 -04:00
|
|
|
class BasicController < ActionController::Base
|
2009-06-17 18:32:55 -04:00
|
|
|
self.view_paths = self.view_paths = [ActionView::FixtureResolver.new(
|
2009-03-23 15:07:34 -04:00
|
|
|
"render_action_with_controller_layout/basic/hello_world.html.erb" => "Hello World!",
|
|
|
|
"layouts/render_action_with_controller_layout/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI"
|
|
|
|
)]
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world
|
|
|
|
render :action => "hello_world"
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_layout
|
|
|
|
render :action => "hello_world", :layout => true
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_layout_false
|
|
|
|
render :action => "hello_world", :layout => false
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_layout_nil
|
|
|
|
render :action => "hello_world", :layout => nil
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_custom_layout
|
|
|
|
render :action => "hello_world", :layout => "greetings"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-05-20 15:15:06 -04:00
|
|
|
class ControllerLayoutTest < SimpleRouteCase
|
|
|
|
describe "Only <controller_path>.html.erb is present and application.html.erb is missing"
|
|
|
|
|
|
|
|
test "render hello_world and implicitly use <controller_path>.html.erb as a layout." do
|
|
|
|
get "/render_action_with_controller_layout/basic/hello_world"
|
|
|
|
|
|
|
|
assert_body "With Controller Layout! Hello World! KTHXBAI"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering with layout => true" do
|
|
|
|
get "/render_action_with_controller_layout/basic/hello_world_with_layout"
|
|
|
|
|
|
|
|
assert_body "With Controller Layout! Hello World! KTHXBAI"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering with layout => false" do
|
|
|
|
get "/render_action_with_controller_layout/basic/hello_world_with_layout_false"
|
|
|
|
|
|
|
|
assert_body "Hello World!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering with layout => :nil" do
|
|
|
|
get "/render_action_with_controller_layout/basic/hello_world_with_layout_nil"
|
|
|
|
|
|
|
|
assert_body "Hello World!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-03-23 15:07:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module RenderActionWithBothLayouts
|
2009-05-01 20:27:44 -04:00
|
|
|
class BasicController < ActionController::Base
|
2009-06-17 18:32:55 -04:00
|
|
|
self.view_paths = [ActionView::FixtureResolver.new({
|
2009-03-23 15:07:34 -04:00
|
|
|
"render_action_with_both_layouts/basic/hello_world.html.erb" => "Hello World!",
|
|
|
|
"layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
|
|
|
|
"layouts/render_action_with_both_layouts/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI"
|
|
|
|
})]
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world
|
|
|
|
render :action => "hello_world"
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_layout
|
|
|
|
render :action => "hello_world", :layout => true
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_layout_false
|
|
|
|
render :action => "hello_world", :layout => false
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-23 15:07:34 -04:00
|
|
|
def hello_world_with_layout_nil
|
|
|
|
render :action => "hello_world", :layout => nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-05-20 15:15:06 -04:00
|
|
|
class ControllerLayoutTest < SimpleRouteCase
|
|
|
|
describe "Both <controller_path>.html.erb and application.html.erb are present"
|
|
|
|
|
|
|
|
test "rendering implicitly use <controller_path>.html.erb over application.html.erb as a layout" do
|
|
|
|
get "/render_action_with_both_layouts/basic/hello_world"
|
|
|
|
|
|
|
|
assert_body "With Controller Layout! Hello World! KTHXBAI"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering with layout => true" do
|
|
|
|
get "/render_action_with_both_layouts/basic/hello_world_with_layout"
|
|
|
|
|
|
|
|
assert_body "With Controller Layout! Hello World! KTHXBAI"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering with layout => false" do
|
|
|
|
get "/render_action_with_both_layouts/basic/hello_world_with_layout_false"
|
|
|
|
|
|
|
|
assert_body "Hello World!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering with layout => :nil" do
|
|
|
|
get "/render_action_with_both_layouts/basic/hello_world_with_layout_nil"
|
|
|
|
|
|
|
|
assert_body "Hello World!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-03-23 15:07:34 -04:00
|
|
|
end
|
2009-03-19 16:35:39 -04:00
|
|
|
end
|