2008-01-05 13:32:06 +00:00
|
|
|
require 'abstract_unit'
|
2006-01-12 07:16:23 +00:00
|
|
|
|
2007-02-04 20:47:05 +00:00
|
|
|
# The view_paths array must be set on Base and not LayoutTest so that LayoutTest's inherited
|
|
|
|
# method has access to the view_paths array when looking for a layout to automatically assign.
|
|
|
|
old_load_paths = ActionController::Base.view_paths
|
2008-11-28 17:18:28 +00:00
|
|
|
|
|
|
|
ActionView::Template::register_template_handler :mab,
|
|
|
|
lambda { |template| template.source.inspect }
|
|
|
|
|
2007-02-04 20:47:05 +00:00
|
|
|
ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/layout_tests/' ]
|
2006-01-12 07:16:23 +00:00
|
|
|
|
|
|
|
class LayoutTest < ActionController::Base
|
|
|
|
def self.controller_path; 'views' end
|
2007-02-04 20:47:05 +00:00
|
|
|
self.view_paths = ActionController::Base.view_paths.dup
|
2006-01-12 07:16:23 +00:00
|
|
|
end
|
|
|
|
|
2007-02-04 20:47:05 +00:00
|
|
|
# Restore view_paths to previous value
|
|
|
|
ActionController::Base.view_paths = old_load_paths
|
2006-01-12 07:16:23 +00:00
|
|
|
|
|
|
|
class ProductController < LayoutTest
|
|
|
|
end
|
|
|
|
|
|
|
|
class ItemController < LayoutTest
|
|
|
|
end
|
|
|
|
|
|
|
|
class ThirdPartyTemplateLibraryController < LayoutTest
|
|
|
|
end
|
|
|
|
|
2006-01-15 11:28:55 +00:00
|
|
|
module ControllerNameSpace
|
|
|
|
end
|
|
|
|
|
|
|
|
class ControllerNameSpace::NestedController < LayoutTest
|
|
|
|
end
|
|
|
|
|
2007-04-12 17:11:48 +00:00
|
|
|
class MultipleExtensions < LayoutTest
|
|
|
|
end
|
|
|
|
|
2008-11-07 20:42:34 +00:00
|
|
|
class LayoutAutoDiscoveryTest < ActionController::TestCase
|
2006-01-12 07:16:23 +00:00
|
|
|
def setup
|
2009-04-09 00:33:06 +00:00
|
|
|
super
|
2006-01-12 07:16:23 +00:00
|
|
|
@request.host = "www.nextangle.com"
|
|
|
|
end
|
2008-08-18 00:29:24 +00:00
|
|
|
|
2006-01-12 07:16:23 +00:00
|
|
|
def test_application_layout_is_default_when_no_controller_match
|
|
|
|
@controller = ProductController.new
|
|
|
|
get :hello
|
|
|
|
assert_equal 'layout_test.rhtml hello.rhtml', @response.body
|
|
|
|
end
|
2008-08-18 00:29:24 +00:00
|
|
|
|
2006-01-12 07:16:23 +00:00
|
|
|
def test_controller_name_layout_name_match
|
|
|
|
@controller = ItemController.new
|
|
|
|
get :hello
|
|
|
|
assert_equal 'item.rhtml hello.rhtml', @response.body
|
|
|
|
end
|
2008-08-18 00:29:24 +00:00
|
|
|
|
2006-01-12 07:16:23 +00:00
|
|
|
def test_third_party_template_library_auto_discovers_layout
|
|
|
|
@controller = ThirdPartyTemplateLibraryController.new
|
|
|
|
get :hello
|
2009-04-23 22:58:38 +00:00
|
|
|
assert @controller.active_layout(true).identifier.include?('layouts/third_party_template_library.mab')
|
2009-04-29 04:29:29 +00:00
|
|
|
assert @controller.template.layout.include?('layouts/third_party_template_library')
|
2008-01-11 04:45:06 +00:00
|
|
|
assert_response :success
|
2006-01-12 07:16:23 +00:00
|
|
|
assert_equal 'Mab', @response.body
|
|
|
|
end
|
2008-08-18 00:29:24 +00:00
|
|
|
|
2006-01-15 11:28:55 +00:00
|
|
|
def test_namespaced_controllers_auto_detect_layouts
|
|
|
|
@controller = ControllerNameSpace::NestedController.new
|
|
|
|
get :hello
|
2009-01-22 22:18:10 +00:00
|
|
|
assert_equal 'layouts/controller_name_space/nested', @controller.active_layout(true).to_s
|
2006-01-15 11:28:55 +00:00
|
|
|
assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body
|
|
|
|
end
|
2008-08-18 00:29:24 +00:00
|
|
|
|
2007-04-12 17:11:48 +00:00
|
|
|
def test_namespaced_controllers_auto_detect_layouts
|
|
|
|
@controller = MultipleExtensions.new
|
|
|
|
get :hello
|
2009-04-23 22:58:38 +00:00
|
|
|
assert @controller.active_layout(true).identifier.include?('layouts/multiple_extensions.html.erb')
|
2007-04-12 17:11:48 +00:00
|
|
|
assert_equal 'multiple_extensions.html.erb hello.rhtml', @response.body.strip
|
|
|
|
end
|
2006-05-17 07:25:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class DefaultLayoutController < LayoutTest
|
|
|
|
end
|
|
|
|
|
2009-03-06 00:49:22 +00:00
|
|
|
class AbsolutePathLayoutController < LayoutTest
|
|
|
|
layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/layouts/layout_test.rhtml')
|
|
|
|
end
|
|
|
|
|
2006-05-17 07:25:36 +00:00
|
|
|
class HasOwnLayoutController < LayoutTest
|
|
|
|
layout 'item'
|
|
|
|
end
|
|
|
|
|
2009-02-20 20:19:45 +00:00
|
|
|
class PrependsViewPathController < LayoutTest
|
|
|
|
def hello
|
|
|
|
prepend_view_path File.dirname(__FILE__) + '/../fixtures/layout_tests/alt/'
|
|
|
|
render :layout => 'alt'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-22 22:18:10 +00:00
|
|
|
class OnlyLayoutController < LayoutTest
|
|
|
|
layout 'item', :only => "hello"
|
|
|
|
end
|
|
|
|
|
|
|
|
class ExceptLayoutController < LayoutTest
|
|
|
|
layout 'item', :except => "goodbye"
|
|
|
|
end
|
|
|
|
|
2006-05-17 07:25:36 +00:00
|
|
|
class SetsLayoutInRenderController < LayoutTest
|
|
|
|
def hello
|
|
|
|
render :layout => 'third_party_template_library'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RendersNoLayoutController < LayoutTest
|
|
|
|
def hello
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-07 20:42:34 +00:00
|
|
|
class LayoutSetInResponseTest < ActionController::TestCase
|
2009-04-23 22:58:38 +00:00
|
|
|
include ActionView::TemplateHandlers
|
|
|
|
|
2006-05-17 07:25:36 +00:00
|
|
|
def test_layout_set_when_using_default_layout
|
|
|
|
@controller = DefaultLayoutController.new
|
|
|
|
get :hello
|
2009-04-29 04:29:29 +00:00
|
|
|
assert @controller.template.layout.include?('layouts/layout_test')
|
2006-05-17 07:25:36 +00:00
|
|
|
end
|
2008-08-18 00:29:24 +00:00
|
|
|
|
2006-05-17 07:25:36 +00:00
|
|
|
def test_layout_set_when_set_in_controller
|
|
|
|
@controller = HasOwnLayoutController.new
|
|
|
|
get :hello
|
2009-04-29 04:29:29 +00:00
|
|
|
assert @controller.template.layout.include?('layouts/item')
|
2006-05-17 07:25:36 +00:00
|
|
|
end
|
2009-01-22 22:18:10 +00:00
|
|
|
|
|
|
|
def test_layout_only_exception_when_included
|
|
|
|
@controller = OnlyLayoutController.new
|
|
|
|
get :hello
|
2009-04-29 04:29:29 +00:00
|
|
|
assert @controller.template.layout.include?('layouts/item')
|
2009-01-22 22:18:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_layout_only_exception_when_excepted
|
|
|
|
@controller = OnlyLayoutController.new
|
|
|
|
get :goodbye
|
2009-04-29 04:29:29 +00:00
|
|
|
assert_equal nil, @controller.template.layout
|
2009-01-22 22:18:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_layout_except_exception_when_included
|
|
|
|
@controller = ExceptLayoutController.new
|
|
|
|
get :hello
|
2009-04-29 04:29:29 +00:00
|
|
|
assert @controller.template.layout.include?('layouts/item')
|
2009-01-22 22:18:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_layout_except_exception_when_excepted
|
|
|
|
@controller = ExceptLayoutController.new
|
|
|
|
get :goodbye
|
2009-04-29 04:29:29 +00:00
|
|
|
assert_equal nil, @controller.template.layout
|
2009-01-22 22:18:10 +00:00
|
|
|
end
|
2008-08-18 00:29:24 +00:00
|
|
|
|
2006-05-17 07:25:36 +00:00
|
|
|
def test_layout_set_when_using_render
|
|
|
|
@controller = SetsLayoutInRenderController.new
|
|
|
|
get :hello
|
2009-04-29 04:29:29 +00:00
|
|
|
assert @controller.template.layout.include?('layouts/third_party_template_library')
|
2006-05-17 07:25:36 +00:00
|
|
|
end
|
2008-08-18 00:29:24 +00:00
|
|
|
|
2006-05-17 07:25:36 +00:00
|
|
|
def test_layout_is_not_set_when_none_rendered
|
|
|
|
@controller = RendersNoLayoutController.new
|
|
|
|
get :hello
|
2009-04-29 04:29:29 +00:00
|
|
|
assert_nil @controller.template.layout
|
2006-05-17 07:25:36 +00:00
|
|
|
end
|
2007-09-30 22:59:24 +00:00
|
|
|
|
|
|
|
def test_exempt_from_layout_honored_by_render_template
|
2009-04-23 22:58:38 +00:00
|
|
|
ActionController::Base.exempt_from_layout :erb
|
2007-09-30 22:59:24 +00:00
|
|
|
@controller = RenderWithTemplateOptionController.new
|
|
|
|
|
|
|
|
get :hello
|
|
|
|
assert_equal "alt/hello.rhtml", @response.body.strip
|
|
|
|
|
|
|
|
ensure
|
2009-04-23 22:58:38 +00:00
|
|
|
ActionController::Base.exempt_from_layout.delete(ERB)
|
2007-09-30 22:59:24 +00:00
|
|
|
end
|
2009-03-06 00:49:22 +00:00
|
|
|
|
2009-02-20 20:19:45 +00:00
|
|
|
def test_layout_is_picked_from_the_controller_instances_view_path
|
2009-04-13 22:18:45 +00:00
|
|
|
pending do
|
|
|
|
@controller = PrependsViewPathController.new
|
|
|
|
get :hello
|
2009-04-29 04:29:29 +00:00
|
|
|
assert_equal 'layouts/alt', @controller.template.layout
|
2009-04-13 22:18:45 +00:00
|
|
|
end
|
2009-02-20 20:19:45 +00:00
|
|
|
end
|
2009-03-06 00:49:22 +00:00
|
|
|
|
|
|
|
def test_absolute_pathed_layout
|
|
|
|
@controller = AbsolutePathLayoutController.new
|
|
|
|
get :hello
|
|
|
|
assert_equal "layout_test.rhtml hello.rhtml", @response.body.strip
|
|
|
|
end
|
2006-07-05 02:38:55 +00:00
|
|
|
end
|
|
|
|
|
2007-09-30 22:59:24 +00:00
|
|
|
class RenderWithTemplateOptionController < LayoutTest
|
|
|
|
def hello
|
|
|
|
render :template => 'alt/hello'
|
|
|
|
end
|
|
|
|
end
|
2006-07-05 02:38:55 +00:00
|
|
|
|
|
|
|
class SetsNonExistentLayoutFile < LayoutTest
|
|
|
|
layout "nofile.rhtml"
|
|
|
|
end
|
|
|
|
|
2008-11-07 20:42:34 +00:00
|
|
|
class LayoutExceptionRaised < ActionController::TestCase
|
2006-07-05 02:38:55 +00:00
|
|
|
def test_exception_raised_when_layout_file_not_found
|
|
|
|
@controller = SetsNonExistentLayoutFile.new
|
|
|
|
get :hello
|
2009-04-29 04:29:29 +00:00
|
|
|
assert_kind_of ActionView::MissingTemplate, @controller.template.instance_eval { @exception }
|
2006-07-05 02:38:55 +00:00
|
|
|
end
|
|
|
|
end
|
2007-09-08 03:12:03 +00:00
|
|
|
|
|
|
|
class LayoutStatusIsRendered < LayoutTest
|
|
|
|
def hello
|
|
|
|
render :status => 401
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-07 20:42:34 +00:00
|
|
|
class LayoutStatusIsRenderedTest < ActionController::TestCase
|
2007-09-08 03:12:03 +00:00
|
|
|
def test_layout_status_is_rendered
|
|
|
|
@controller = LayoutStatusIsRendered.new
|
|
|
|
get :hello
|
|
|
|
assert_response 401
|
|
|
|
end
|
|
|
|
end
|
2008-03-28 20:54:26 +00:00
|
|
|
|
2008-12-27 17:28:28 +00:00
|
|
|
unless RUBY_PLATFORM =~ /(:?mswin|mingw|bccwin)/
|
|
|
|
class LayoutSymlinkedTest < LayoutTest
|
|
|
|
layout "symlinked/symlinked_layout"
|
|
|
|
end
|
|
|
|
|
|
|
|
class LayoutSymlinkedIsRenderedTest < ActionController::TestCase
|
|
|
|
def test_symlinked_layout_is_rendered
|
|
|
|
@controller = LayoutSymlinkedTest.new
|
|
|
|
get :hello
|
|
|
|
assert_response 200
|
2009-04-29 04:29:29 +00:00
|
|
|
assert @controller.template.layout.include?("layouts/symlinked/symlinked_layout")
|
2008-12-27 17:28:28 +00:00
|
|
|
end
|
2008-03-28 20:54:26 +00:00
|
|
|
end
|
|
|
|
end
|