1 require 'abstract_unit'
3 # The view_paths array must be set on Base and not LayoutTest so that LayoutTest's inherited
4 # method has access to the view_paths array when looking for a layout to automatically assign.
5 old_load_paths
= ActionController
::Base.view_paths
7 ActionView
::Template::register_template_handler :mab,
8 lambda
{ |template
| template
.source
.inspect
}
10 ActionController
::Base.view_paths
= [ File
.dirname(__FILE__
) + '/../fixtures/layout_tests/' ]
12 class LayoutTest
< ActionController
::Base
13 def self.controller_path
; 'views' end
14 self.view_paths
= ActionController
::Base.view_paths
.dup
17 # Restore view_paths to previous value
18 ActionController
::Base.view_paths
= old_load_paths
20 class ProductController
< LayoutTest
23 class ItemController
< LayoutTest
26 class ThirdPartyTemplateLibraryController
< LayoutTest
29 module ControllerNameSpace
32 class ControllerNameSpace
::NestedController < LayoutTest
35 class MultipleExtensions
< LayoutTest
38 class LayoutAutoDiscoveryTest
< ActionController
::TestCase
40 @request.host
= "www.nextangle.com"
43 def test_application_layout_is_default_when_no_controller_match
44 @controller = ProductController
.new
46 assert_equal
'layout_test.rhtml hello.rhtml', @response.body
49 def test_controller_name_layout_name_match
50 @controller = ItemController
.new
52 assert_equal
'item.rhtml hello.rhtml', @response.body
55 def test_third_party_template_library_auto_discovers_layout
56 @controller = ThirdPartyTemplateLibraryController
.new
58 assert_equal
'layouts/third_party_template_library.mab', @controller.active_layout
.to_s
59 assert_equal
'layouts/third_party_template_library', @response.layout
60 assert_response
:success
61 assert_equal
'Mab', @response.body
64 def test_namespaced_controllers_auto_detect_layouts
65 @controller = ControllerNameSpace
::NestedController.new
67 assert_equal
'layouts/controller_name_space/nested', @controller.active_layout
.to_s
68 assert_equal
'controller_name_space/nested.rhtml hello.rhtml', @response.body
71 def test_namespaced_controllers_auto_detect_layouts
72 @controller = MultipleExtensions
.new
74 assert_equal
'layouts/multiple_extensions.html.erb', @controller.active_layout
.to_s
75 assert_equal
'multiple_extensions.html.erb hello.rhtml', @response.body
.strip
79 class DefaultLayoutController
< LayoutTest
82 class AbsolutePathLayoutController
< LayoutTest
83 layout File
.expand_path(File
.expand_path(__FILE__
) + '/../../fixtures/layout_tests/layouts/layout_test.rhtml')
86 class HasOwnLayoutController
< LayoutTest
90 class PrependsViewPathController
< LayoutTest
92 prepend_view_path File
.dirname(__FILE__
) + '/../fixtures/layout_tests/alt/'
93 render
:layout => 'alt'
97 class SetsLayoutInRenderController
< LayoutTest
99 render
:layout => 'third_party_template_library'
103 class RendersNoLayoutController
< LayoutTest
105 render
:layout => false
109 class LayoutSetInResponseTest
< ActionController
::TestCase
110 def test_layout_set_when_using_default_layout
111 @controller = DefaultLayoutController
.new
113 assert_equal
'layouts/layout_test', @response.layout
116 def test_layout_set_when_set_in_controller
117 @controller = HasOwnLayoutController
.new
119 assert_equal
'layouts/item', @response.layout
122 def test_layout_set_when_using_render
123 @controller = SetsLayoutInRenderController
.new
125 assert_equal
'layouts/third_party_template_library', @response.layout
128 def test_layout_is_not_set_when_none_rendered
129 @controller = RendersNoLayoutController
.new
131 assert_nil
@response.layout
134 def test_exempt_from_layout_honored_by_render_template
135 ActionController
::Base.exempt_from_layout
:rhtml
136 @controller = RenderWithTemplateOptionController
.new
139 assert_equal
"alt/hello.rhtml", @response.body
.strip
142 ActionController
::Base.exempt_from_layout
.delete(/\.rhtml$/)
145 def test_layout_is_picked_from_the_controller_instances_view_path
146 @controller = PrependsViewPathController
.new
148 assert_equal
'layouts/alt', @response.layout
151 def test_absolute_pathed_layout
152 @controller = AbsolutePathLayoutController
.new
154 assert_equal
"layout_test.rhtml hello.rhtml", @response.body
.strip
158 class RenderWithTemplateOptionController
< LayoutTest
160 render
:template => 'alt/hello'
164 class SetsNonExistentLayoutFile
< LayoutTest
165 layout
"nofile.rhtml"
168 class LayoutExceptionRaised
< ActionController
::TestCase
169 def test_exception_raised_when_layout_file_not_found
170 @controller = SetsNonExistentLayoutFile
.new
172 assert_kind_of ActionView
::MissingTemplate, @response.template
.instance_eval
{ @exception }
176 class LayoutStatusIsRendered
< LayoutTest
178 render
:status => 401
182 class LayoutStatusIsRenderedTest
< ActionController
::TestCase
183 def test_layout_status_is_rendered
184 @controller = LayoutStatusIsRendered
.new
190 unless RUBY_PLATFORM =~
/(:?mswin|mingw|bccwin)/
191 class LayoutSymlinkedTest
< LayoutTest
192 layout
"symlinked/symlinked_layout"
195 class LayoutSymlinkedIsRenderedTest
< ActionController
::TestCase
196 def test_symlinked_layout_is_rendered
197 @controller = LayoutSymlinkedTest
.new
200 assert_equal
"layouts/symlinked/symlinked_layout", @response.layout