2009-09-19 13:10:41 -04:00
|
|
|
require 'abstract_unit'
|
2009-04-07 20:57:20 -04:00
|
|
|
|
|
|
|
module ControllerLayouts
|
|
|
|
class ImplicitController < ::ApplicationController
|
2009-06-17 18:32:55 -04:00
|
|
|
self.view_paths = [ActionView::FixtureResolver.new(
|
2010-01-31 00:27:24 -05:00
|
|
|
"layouts/application.html.erb" => "Main <%= yield %> Layout",
|
2009-05-01 14:40:32 -04:00
|
|
|
"layouts/override.html.erb" => "Override! <%= yield %>",
|
2009-05-13 20:00:36 -04:00
|
|
|
"basic.html.erb" => "Hello world!",
|
2010-01-31 00:27:24 -05:00
|
|
|
"controller_layouts/implicit/layout_false.html.erb" => "hi(layout_false.html.erb)"
|
2009-04-07 20:57:20 -04:00
|
|
|
)]
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-04-07 20:57:20 -04:00
|
|
|
def index
|
|
|
|
render :template => "basic"
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-05-01 14:40:32 -04:00
|
|
|
def override
|
|
|
|
render :template => "basic", :layout => "override"
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
def layout_false
|
|
|
|
render :layout => false
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-05-01 14:40:32 -04:00
|
|
|
def builder_override
|
|
|
|
end
|
2009-04-07 20:57:20 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-04-07 20:57:20 -04:00
|
|
|
class ImplicitNameController < ::ApplicationController
|
2009-06-17 18:32:55 -04:00
|
|
|
self.view_paths = [ActionView::FixtureResolver.new(
|
2010-01-31 00:27:24 -05:00
|
|
|
"layouts/controller_layouts/implicit_name.html.erb" => "Implicit <%= yield %> Layout",
|
2009-04-07 20:57:20 -04:00
|
|
|
"basic.html.erb" => "Hello world!"
|
|
|
|
)]
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-04-07 20:57:20 -04:00
|
|
|
def index
|
|
|
|
render :template => "basic"
|
|
|
|
end
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-10-04 00:18:32 -04:00
|
|
|
class RenderLayoutTest < Rack::TestCase
|
2009-05-20 15:15:06 -04:00
|
|
|
test "rendering a normal template, but using the implicit layout" do
|
|
|
|
get "/controller_layouts/implicit/index"
|
|
|
|
|
2010-01-31 00:27:24 -05:00
|
|
|
assert_body "Main Hello world! Layout"
|
2009-05-20 15:15:06 -04:00
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rendering a normal template, but using an implicit NAMED layout" do
|
|
|
|
get "/controller_layouts/implicit_name/index"
|
|
|
|
|
2010-01-31 00:27:24 -05:00
|
|
|
assert_body "Implicit Hello world! Layout"
|
2009-05-20 15:15:06 -04:00
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "overriding an implicit layout with render :layout option" do
|
|
|
|
get "/controller_layouts/implicit/override"
|
|
|
|
assert_body "Override! Hello world!"
|
|
|
|
end
|
|
|
|
|
2009-05-01 14:40:32 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-10-04 00:18:32 -04:00
|
|
|
class LayoutOptionsTest < Rack::TestCase
|
2009-05-13 20:00:36 -04:00
|
|
|
testing ControllerLayouts::ImplicitController
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
test "rendering with :layout => false leaves out the implicit layout" do
|
|
|
|
get :layout_false
|
2010-01-31 00:27:24 -05:00
|
|
|
assert_response "hi(layout_false.html.erb)"
|
2009-05-13 20:00:36 -04:00
|
|
|
end
|
|
|
|
end
|
2009-05-23 03:39:32 -04:00
|
|
|
|
|
|
|
class MismatchFormatController < ::ApplicationController
|
2009-06-17 18:32:55 -04:00
|
|
|
self.view_paths = [ActionView::FixtureResolver.new(
|
2009-05-23 03:39:32 -04:00
|
|
|
"layouts/application.html.erb" => "<html><%= yield %></html>",
|
2011-03-25 18:12:09 -04:00
|
|
|
"controller_layouts/mismatch_format/index.xml.builder" => "xml.instruct!",
|
2011-12-08 14:59:43 -05:00
|
|
|
"controller_layouts/mismatch_format/implicit.builder" => "xml.instruct!",
|
|
|
|
"controller_layouts/mismatch_format/explicit.js.erb" => "alert('foo');"
|
2009-05-23 03:39:32 -04:00
|
|
|
)]
|
|
|
|
|
|
|
|
def explicit
|
|
|
|
render :layout => "application"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-04 00:18:32 -04:00
|
|
|
class MismatchFormatTest < Rack::TestCase
|
2009-05-23 03:39:32 -04:00
|
|
|
testing ControllerLayouts::MismatchFormatController
|
2011-12-08 16:56:50 -05:00
|
|
|
|
2011-03-25 18:12:09 -04:00
|
|
|
XML_INSTRUCT = %Q(<?xml version="1.0" encoding="UTF-8"?>\n)
|
2009-05-23 03:39:32 -04:00
|
|
|
|
2011-03-25 18:12:09 -04:00
|
|
|
test "if XML is selected, an HTML template is not also selected" do
|
2015-01-29 09:19:41 -05:00
|
|
|
get :index, params: { format: "xml" }
|
2011-03-25 18:12:09 -04:00
|
|
|
assert_response XML_INSTRUCT
|
2009-05-23 03:39:32 -04:00
|
|
|
end
|
|
|
|
|
2011-03-25 18:12:09 -04:00
|
|
|
test "if XML is implicitly selected, an HTML template is not also selected" do
|
2009-05-23 03:39:32 -04:00
|
|
|
get :implicit
|
2011-03-25 18:12:09 -04:00
|
|
|
assert_response XML_INSTRUCT
|
2009-05-23 03:39:32 -04:00
|
|
|
end
|
|
|
|
|
2011-12-08 14:59:43 -05:00
|
|
|
test "a layout for JS is ignored even if explicitly provided for HTML" do
|
2015-01-29 09:19:41 -05:00
|
|
|
get :explicit, params: { format: "js" }
|
2011-12-08 14:59:43 -05:00
|
|
|
assert_response "alert('foo');"
|
2009-05-23 03:39:32 -04:00
|
|
|
end
|
|
|
|
end
|
2011-12-08 16:56:50 -05:00
|
|
|
|
|
|
|
class FalseLayoutMethodController < ::ApplicationController
|
|
|
|
self.view_paths = [ActionView::FixtureResolver.new(
|
|
|
|
"controller_layouts/false_layout_method/index.js.erb" => "alert('foo');"
|
|
|
|
)]
|
|
|
|
|
|
|
|
layout :which_layout?
|
|
|
|
|
|
|
|
def which_layout?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class FalseLayoutMethodTest < Rack::TestCase
|
|
|
|
testing ControllerLayouts::FalseLayoutMethodController
|
|
|
|
|
|
|
|
test "access false layout returned by a method/proc" do
|
2015-01-29 09:19:41 -05:00
|
|
|
get :index, params: { format: "js" }
|
2011-12-08 16:56:50 -05:00
|
|
|
assert_response "alert('foo');"
|
|
|
|
end
|
|
|
|
end
|
2009-09-13 17:30:27 -04:00
|
|
|
end
|