2008-01-05 08:32:06 -05:00
|
|
|
require 'abstract_unit'
|
2010-04-26 11:25:07 -04:00
|
|
|
require 'rbconfig'
|
2006-01-12 02:16:23 -05:00
|
|
|
|
2007-02-04 15:47:05 -05: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 12:18:28 -05:00
|
|
|
|
|
|
|
ActionView::Template::register_template_handler :mab,
|
|
|
|
lambda { |template| template.source.inspect }
|
|
|
|
|
2007-02-04 15:47:05 -05:00
|
|
|
ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/layout_tests/' ]
|
2006-01-12 02:16:23 -05:00
|
|
|
|
|
|
|
class LayoutTest < ActionController::Base
|
|
|
|
def self.controller_path; 'views' end
|
2009-05-21 21:14:20 -04:00
|
|
|
def self._implied_layout_name; to_s.underscore.gsub(/_controller$/, '') ; end
|
2007-02-04 15:47:05 -05:00
|
|
|
self.view_paths = ActionController::Base.view_paths.dup
|
2006-01-12 02:16:23 -05:00
|
|
|
end
|
|
|
|
|
2007-02-04 15:47:05 -05:00
|
|
|
# Restore view_paths to previous value
|
|
|
|
ActionController::Base.view_paths = old_load_paths
|
2006-01-12 02:16:23 -05:00
|
|
|
|
|
|
|
class ProductController < LayoutTest
|
|
|
|
end
|
|
|
|
|
|
|
|
class ItemController < LayoutTest
|
|
|
|
end
|
|
|
|
|
|
|
|
class ThirdPartyTemplateLibraryController < LayoutTest
|
|
|
|
end
|
|
|
|
|
2006-01-15 06:28:55 -05:00
|
|
|
module ControllerNameSpace
|
|
|
|
end
|
|
|
|
|
|
|
|
class ControllerNameSpace::NestedController < LayoutTest
|
|
|
|
end
|
|
|
|
|
2007-04-12 13:11:48 -04:00
|
|
|
class MultipleExtensions < LayoutTest
|
|
|
|
end
|
|
|
|
|
2008-11-07 15:42:34 -05:00
|
|
|
class LayoutAutoDiscoveryTest < ActionController::TestCase
|
2006-01-12 02:16:23 -05:00
|
|
|
def setup
|
2009-04-08 20:33:06 -04:00
|
|
|
super
|
2006-01-12 02:16:23 -05:00
|
|
|
@request.host = "www.nextangle.com"
|
|
|
|
end
|
2008-08-17 20:29:24 -04:00
|
|
|
|
2006-01-12 02:16:23 -05:00
|
|
|
def test_application_layout_is_default_when_no_controller_match
|
|
|
|
@controller = ProductController.new
|
|
|
|
get :hello
|
2010-10-09 19:14:50 -04:00
|
|
|
assert_equal 'layout_test.erb hello.erb', @response.body
|
2006-01-12 02:16:23 -05:00
|
|
|
end
|
2008-08-17 20:29:24 -04:00
|
|
|
|
2006-01-12 02:16:23 -05:00
|
|
|
def test_controller_name_layout_name_match
|
|
|
|
@controller = ItemController.new
|
|
|
|
get :hello
|
2010-10-09 19:14:50 -04:00
|
|
|
assert_equal 'item.erb hello.erb', @response.body
|
2006-01-12 02:16:23 -05:00
|
|
|
end
|
2008-08-17 20:29:24 -04:00
|
|
|
|
2006-01-12 02:16:23 -05:00
|
|
|
def test_third_party_template_library_auto_discovers_layout
|
|
|
|
@controller = ThirdPartyTemplateLibraryController.new
|
|
|
|
get :hello
|
2008-01-10 23:45:06 -05:00
|
|
|
assert_response :success
|
2009-05-21 21:14:20 -04:00
|
|
|
assert_equal 'layouts/third_party_template_library.mab', @response.body
|
2006-01-12 02:16:23 -05:00
|
|
|
end
|
2008-08-17 20:29:24 -04:00
|
|
|
|
2009-05-21 21:14:20 -04:00
|
|
|
def test_namespaced_controllers_auto_detect_layouts1
|
2006-01-15 06:28:55 -05:00
|
|
|
@controller = ControllerNameSpace::NestedController.new
|
|
|
|
get :hello
|
2010-10-09 19:14:50 -04:00
|
|
|
assert_equal 'controller_name_space/nested.erb hello.erb', @response.body
|
2006-01-15 06:28:55 -05:00
|
|
|
end
|
2008-08-17 20:29:24 -04:00
|
|
|
|
2009-05-21 21:14:20 -04:00
|
|
|
def test_namespaced_controllers_auto_detect_layouts2
|
2007-04-12 13:11:48 -04:00
|
|
|
@controller = MultipleExtensions.new
|
|
|
|
get :hello
|
2010-10-09 19:14:50 -04:00
|
|
|
assert_equal 'multiple_extensions.html.erb hello.erb', @response.body.strip
|
2007-04-12 13:11:48 -04:00
|
|
|
end
|
2006-05-17 03:25:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class DefaultLayoutController < LayoutTest
|
|
|
|
end
|
|
|
|
|
2009-03-05 19:49:22 -05:00
|
|
|
class AbsolutePathLayoutController < LayoutTest
|
2011-09-22 09:37:38 -04:00
|
|
|
layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/layouts/layout_test')
|
2009-03-05 19:49:22 -05:00
|
|
|
end
|
|
|
|
|
2006-05-17 03:25:36 -04:00
|
|
|
class HasOwnLayoutController < LayoutTest
|
|
|
|
layout 'item'
|
|
|
|
end
|
|
|
|
|
2009-02-20 15:19:45 -05:00
|
|
|
class PrependsViewPathController < LayoutTest
|
|
|
|
def hello
|
|
|
|
prepend_view_path File.dirname(__FILE__) + '/../fixtures/layout_tests/alt/'
|
|
|
|
render :layout => 'alt'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-22 17:18:10 -05:00
|
|
|
class OnlyLayoutController < LayoutTest
|
|
|
|
layout 'item', :only => "hello"
|
|
|
|
end
|
|
|
|
|
|
|
|
class ExceptLayoutController < LayoutTest
|
|
|
|
layout 'item', :except => "goodbye"
|
|
|
|
end
|
|
|
|
|
2006-05-17 03:25:36 -04: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 15:42:34 -05:00
|
|
|
class LayoutSetInResponseTest < ActionController::TestCase
|
2009-12-02 23:01:01 -05:00
|
|
|
include ActionView::Template::Handlers
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2006-05-17 03:25:36 -04:00
|
|
|
def test_layout_set_when_using_default_layout
|
|
|
|
@controller = DefaultLayoutController.new
|
|
|
|
get :hello
|
2010-03-17 19:28:05 -04:00
|
|
|
assert_template :layout => "layouts/layout_test"
|
2006-05-17 03:25:36 -04:00
|
|
|
end
|
2008-08-17 20:29:24 -04:00
|
|
|
|
2006-05-17 03:25:36 -04:00
|
|
|
def test_layout_set_when_set_in_controller
|
|
|
|
@controller = HasOwnLayoutController.new
|
|
|
|
get :hello
|
2010-03-17 19:28:05 -04:00
|
|
|
assert_template :layout => "layouts/item"
|
2006-05-17 03:25:36 -04:00
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-01-22 17:18:10 -05:00
|
|
|
def test_layout_only_exception_when_included
|
|
|
|
@controller = OnlyLayoutController.new
|
|
|
|
get :hello
|
2010-03-17 19:28:05 -04:00
|
|
|
assert_template :layout => "layouts/item"
|
2009-01-22 17:18:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_layout_only_exception_when_excepted
|
|
|
|
@controller = OnlyLayoutController.new
|
|
|
|
get :goodbye
|
2010-10-09 19:14:50 -04:00
|
|
|
assert !@response.body.include?("item.erb"), "#{@response.body.inspect} included 'item.erb'"
|
2009-01-22 17:18:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_layout_except_exception_when_included
|
|
|
|
@controller = ExceptLayoutController.new
|
|
|
|
get :hello
|
2010-03-17 19:28:05 -04:00
|
|
|
assert_template :layout => "layouts/item"
|
2009-01-22 17:18:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_layout_except_exception_when_excepted
|
|
|
|
@controller = ExceptLayoutController.new
|
|
|
|
get :goodbye
|
2010-10-09 19:14:50 -04:00
|
|
|
assert !@response.body.include?("item.erb"), "#{@response.body.inspect} included 'item.erb'"
|
2009-01-22 17:18:10 -05:00
|
|
|
end
|
2008-08-17 20:29:24 -04:00
|
|
|
|
2006-05-17 03:25:36 -04:00
|
|
|
def test_layout_set_when_using_render
|
|
|
|
@controller = SetsLayoutInRenderController.new
|
|
|
|
get :hello
|
2010-03-17 19:28:05 -04:00
|
|
|
assert_template :layout => "layouts/third_party_template_library"
|
2006-05-17 03:25:36 -04:00
|
|
|
end
|
2008-08-17 20:29:24 -04:00
|
|
|
|
2006-05-17 03:25:36 -04:00
|
|
|
def test_layout_is_not_set_when_none_rendered
|
|
|
|
@controller = RendersNoLayoutController.new
|
|
|
|
get :hello
|
2010-03-17 19:28:05 -04:00
|
|
|
assert_template :layout => nil
|
2006-05-17 03:25:36 -04:00
|
|
|
end
|
2007-09-30 18:59:24 -04:00
|
|
|
|
2009-02-20 15:19:45 -05:00
|
|
|
def test_layout_is_picked_from_the_controller_instances_view_path
|
2009-06-17 15:00:23 -04:00
|
|
|
@controller = PrependsViewPathController.new
|
|
|
|
get :hello
|
2011-12-02 13:13:36 -05:00
|
|
|
assert_template :layout => /layouts\/alt/
|
2009-02-20 15:19:45 -05:00
|
|
|
end
|
2009-03-05 19:49:22 -05:00
|
|
|
|
|
|
|
def test_absolute_pathed_layout
|
|
|
|
@controller = AbsolutePathLayoutController.new
|
|
|
|
get :hello
|
2010-10-09 19:14:50 -04:00
|
|
|
assert_equal "layout_test.erb hello.erb", @response.body.strip
|
2009-03-05 19:49:22 -05:00
|
|
|
end
|
2006-07-04 22:38:55 -04:00
|
|
|
end
|
|
|
|
|
2007-09-30 18:59:24 -04:00
|
|
|
class RenderWithTemplateOptionController < LayoutTest
|
|
|
|
def hello
|
|
|
|
render :template => 'alt/hello'
|
|
|
|
end
|
|
|
|
end
|
2006-07-04 22:38:55 -04:00
|
|
|
|
|
|
|
class SetsNonExistentLayoutFile < LayoutTest
|
2011-09-22 09:37:38 -04:00
|
|
|
layout "nofile"
|
2006-07-04 22:38:55 -04:00
|
|
|
end
|
|
|
|
|
2008-11-07 15:42:34 -05:00
|
|
|
class LayoutExceptionRaised < ActionController::TestCase
|
2006-07-04 22:38:55 -04:00
|
|
|
def test_exception_raised_when_layout_file_not_found
|
|
|
|
@controller = SetsNonExistentLayoutFile.new
|
2009-05-03 00:02:22 -04:00
|
|
|
assert_raise(ActionView::MissingTemplate) { get :hello }
|
2006-07-04 22:38:55 -04:00
|
|
|
end
|
|
|
|
end
|
2007-09-07 23:12:03 -04:00
|
|
|
|
|
|
|
class LayoutStatusIsRendered < LayoutTest
|
|
|
|
def hello
|
|
|
|
render :status => 401
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-07 15:42:34 -05:00
|
|
|
class LayoutStatusIsRenderedTest < ActionController::TestCase
|
2007-09-07 23:12:03 -04:00
|
|
|
def test_layout_status_is_rendered
|
|
|
|
@controller = LayoutStatusIsRendered.new
|
|
|
|
get :hello
|
|
|
|
assert_response 401
|
|
|
|
end
|
|
|
|
end
|
2008-03-28 16:54:26 -04:00
|
|
|
|
2010-08-23 22:09:35 -04:00
|
|
|
unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
2008-12-27 12:28:28 -05:00
|
|
|
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
|
2010-03-17 19:28:05 -04:00
|
|
|
assert_template :layout => "layouts/symlinked/symlinked_layout"
|
2008-12-27 12:28:28 -05:00
|
|
|
end
|
2008-03-28 16:54:26 -04:00
|
|
|
end
|
|
|
|
end
|