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
6 ActionController
::Base.view_paths
= [ File
.dirname(__FILE__
) + '/../fixtures/layout_tests/' ]
8 class LayoutTest
< ActionController
::Base
9 def self.controller_path
; 'views' end
10 self.view_paths
= ActionController
::Base.view_paths
.dup
13 # Restore view_paths to previous value
14 ActionController
::Base.view_paths
= old_load_paths
16 class ProductController
< LayoutTest
19 class ItemController
< LayoutTest
22 class ThirdPartyTemplateLibraryController
< LayoutTest
25 module ControllerNameSpace
28 class ControllerNameSpace
::NestedController < LayoutTest
31 class MultipleExtensions
< LayoutTest
34 ActionView
::Template::register_template_handler :mab,
35 lambda
{ |template
| template
.source
.inspect
}
37 class LayoutAutoDiscoveryTest
< Test
::Unit::TestCase
39 @request = ActionController
::TestRequest.new
40 @response = ActionController
::TestResponse.new
42 @request.host
= "www.nextangle.com"
45 def test_application_layout_is_default_when_no_controller_match
46 @controller = ProductController
.new
48 assert_equal
'layout_test.rhtml hello.rhtml', @response.body
51 def test_controller_name_layout_name_match
52 @controller = ItemController
.new
54 assert_equal
'item.rhtml hello.rhtml', @response.body
57 def test_third_party_template_library_auto_discovers_layout
58 ThirdPartyTemplateLibraryController
.view_paths
.reload
!
59 @controller = ThirdPartyTemplateLibraryController
.new
61 assert_equal
'layouts/third_party_template_library', @controller.active_layout
62 assert_equal
'layouts/third_party_template_library', @response.layout
63 assert_response
:success
64 assert_equal
'Mab', @response.body
67 def test_namespaced_controllers_auto_detect_layouts
68 @controller = ControllerNameSpace
::NestedController.new
70 assert_equal
'layouts/controller_name_space/nested', @controller.active_layout
71 assert_equal
'controller_name_space/nested.rhtml hello.rhtml', @response.body
74 def test_namespaced_controllers_auto_detect_layouts
75 @controller = MultipleExtensions
.new
77 assert_equal
'layouts/multiple_extensions', @controller.active_layout
78 assert_equal
'multiple_extensions.html.erb hello.rhtml', @response.body
.strip
82 class DefaultLayoutController
< LayoutTest
85 class HasOwnLayoutController
< LayoutTest
89 class SetsLayoutInRenderController
< LayoutTest
91 render
:layout => 'third_party_template_library'
95 class RendersNoLayoutController
< LayoutTest
97 render
:layout => false
101 class LayoutSetInResponseTest
< Test
::Unit::TestCase
103 @request = ActionController
::TestRequest.new
104 @response = ActionController
::TestResponse.new
107 def test_layout_set_when_using_default_layout
108 @controller = DefaultLayoutController
.new
110 assert_equal
'layouts/layout_test', @response.layout
113 def test_layout_set_when_set_in_controller
114 @controller = HasOwnLayoutController
.new
116 assert_equal
'layouts/item', @response.layout
119 def test_layout_set_when_using_render
120 @controller = SetsLayoutInRenderController
.new
122 assert_equal
'layouts/third_party_template_library', @response.layout
125 def test_layout_is_not_set_when_none_rendered
126 @controller = RendersNoLayoutController
.new
128 assert_nil
@response.layout
131 def test_exempt_from_layout_honored_by_render_template
132 ActionController
::Base.exempt_from_layout
:rhtml
133 @controller = RenderWithTemplateOptionController
.new
136 assert_equal
"alt/hello.rhtml", @response.body
.strip
139 ActionController
::Base.exempt_from_layout
.delete(/\.rhtml$/)
143 class RenderWithTemplateOptionController
< LayoutTest
145 render
:template => 'alt/hello'
149 class SetsNonExistentLayoutFile
< LayoutTest
150 layout
"nofile.rhtml"
153 class LayoutExceptionRaised
< Test
::Unit::TestCase
155 @request = ActionController
::TestRequest.new
156 @response = ActionController
::TestResponse.new
159 def test_exception_raised_when_layout_file_not_found
160 @controller = SetsNonExistentLayoutFile
.new
162 @response.template
.class.module_eval
{ attr_accessor
:exception }
163 assert_equal ActionView
::MissingTemplate, @response.template
.exception
.class
167 class LayoutStatusIsRendered
< LayoutTest
169 render
:status => 401
173 class LayoutStatusIsRenderedTest
< Test
::Unit::TestCase
175 @request = ActionController
::TestRequest.new
176 @response = ActionController
::TestResponse.new
179 def test_layout_status_is_rendered
180 @controller = LayoutStatusIsRendered
.new
186 class LayoutSymlinkedTest
< LayoutTest
187 layout
"symlinked/symlinked_layout"
190 class LayoutSymlinkedIsRenderedTest
< Test
::Unit::TestCase
192 @request = ActionController
::TestRequest.new
193 @response = ActionController
::TestResponse.new
196 def test_symlinked_layout_is_rendered
197 @controller = LayoutSymlinkedTest
.new
200 assert_equal
"layouts/symlinked/symlinked_layout", @response.layout