diff options
author | Łukasz Strzałkowski <lukasz.strzalkowski@gmail.com> | 2013-08-07 00:18:52 +0200 |
---|---|---|
committer | Łukasz Strzałkowski <lukasz.strzalkowski@gmail.com> | 2013-08-25 11:39:14 +0200 |
commit | c9ef9c1442f0b33a0641466398801aa69ce141f1 (patch) | |
tree | 55dd9a7512b86befc81187a2eddb33690555f4bc /actionview | |
parent | 53e65e177210ae4fc7958a2e4b082b1a80d274d6 (diff) | |
download | rails-c9ef9c1442f0b33a0641466398801aa69ce141f1.tar.gz rails-c9ef9c1442f0b33a0641466398801aa69ce141f1.tar.bz2 rails-c9ef9c1442f0b33a0641466398801aa69ce141f1.zip |
Move remaining layouts tests to AV
Diffstat (limited to 'actionview')
17 files changed, 288 insertions, 0 deletions
diff --git a/actionview/test/actionpack/layout_test.rb b/actionview/test/actionpack/layout_test.rb new file mode 100644 index 0000000000..e8b7c56019 --- /dev/null +++ b/actionview/test/actionpack/layout_test.rb @@ -0,0 +1,262 @@ +require 'abstract_unit' +require 'rbconfig' +require 'active_support/core_ext/array/extract_options' + +# 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 + +ActionView::Template::register_template_handler :mab, + lambda { |template| template.source.inspect } + +ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/actionpack/layout_tests/' ] + +class LayoutTest < ActionController::Base + def self.controller_path; 'views' end + def self._implied_layout_name; to_s.underscore.gsub(/_controller$/, '') ; end + self.view_paths = ActionController::Base.view_paths.dup +end + +# Restore view_paths to previous value +ActionController::Base.view_paths = old_load_paths + +class ProductController < LayoutTest +end + +class ItemController < LayoutTest +end + +class ThirdPartyTemplateLibraryController < LayoutTest +end + +module ControllerNameSpace +end + +class ControllerNameSpace::NestedController < LayoutTest +end + +class MultipleExtensions < LayoutTest +end + +class LayoutAutoDiscoveryTest < ActionController::TestCase + def setup + super + @request.host = "www.nextangle.com" + end + + def test_application_layout_is_default_when_no_controller_match + @controller = ProductController.new + get :hello + assert_equal 'layout_test.erb hello.erb', @response.body + end + + def test_controller_name_layout_name_match + @controller = ItemController.new + get :hello + assert_equal 'item.erb hello.erb', @response.body + end + + def test_third_party_template_library_auto_discovers_layout + @controller = ThirdPartyTemplateLibraryController.new + get :hello + assert_response :success + assert_equal 'layouts/third_party_template_library.mab', @response.body + end + + def test_namespaced_controllers_auto_detect_layouts1 + @controller = ControllerNameSpace::NestedController.new + get :hello + assert_equal 'controller_name_space/nested.erb hello.erb', @response.body + end + + def test_namespaced_controllers_auto_detect_layouts2 + @controller = MultipleExtensions.new + get :hello + assert_equal 'multiple_extensions.html.erb hello.erb', @response.body.strip + end +end + +class DefaultLayoutController < LayoutTest +end + +class StreamingLayoutController < LayoutTest + def render(*args) + options = args.extract_options! + super(*args, options.merge(:stream => true)) + end +end + +class AbsolutePathLayoutController < LayoutTest + layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/actionpack/layout_tests/layouts/layout_test') +end + +class HasOwnLayoutController < LayoutTest + layout 'item' +end + +class HasNilLayoutSymbol < LayoutTest + layout :nilz + + def nilz + nil + end +end + +class HasNilLayoutProc < LayoutTest + layout proc { nil } +end + +class PrependsViewPathController < LayoutTest + def hello + prepend_view_path File.dirname(__FILE__) + '/../fixtures/actionpack/layout_tests/alt/' + render :layout => 'alt' + end +end + +class OnlyLayoutController < LayoutTest + layout 'item', :only => "hello" +end + +class ExceptLayoutController < LayoutTest + layout 'item', :except => "goodbye" +end + +class SetsLayoutInRenderController < LayoutTest + def hello + render :layout => 'third_party_template_library' + end +end + +class RendersNoLayoutController < LayoutTest + def hello + render :layout => false + end +end + +class LayoutSetInResponseTest < ActionController::TestCase + include ActionView::Template::Handlers + + def test_layout_set_when_using_default_layout + @controller = DefaultLayoutController.new + get :hello + assert_template :layout => "layouts/layout_test" + end + + def test_layout_set_when_using_streaming_layout + @controller = StreamingLayoutController.new + get :hello + assert_template :hello + end + + def test_layout_set_when_set_in_controller + @controller = HasOwnLayoutController.new + get :hello + assert_template :layout => "layouts/item" + end + + def test_layout_symbol_set_in_controller_returning_nil_falls_back_to_default + @controller = HasNilLayoutSymbol.new + get :hello + assert_template layout: "layouts/layout_test" + end + + def test_layout_proc_set_in_controller_returning_nil_falls_back_to_default + @controller = HasNilLayoutProc.new + get :hello + assert_template layout: "layouts/layout_test" + end + + def test_layout_only_exception_when_included + @controller = OnlyLayoutController.new + get :hello + assert_template :layout => "layouts/item" + end + + def test_layout_only_exception_when_excepted + @controller = OnlyLayoutController.new + get :goodbye + assert !@response.body.include?("item.erb"), "#{@response.body.inspect} included 'item.erb'" + end + + def test_layout_except_exception_when_included + @controller = ExceptLayoutController.new + get :hello + assert_template :layout => "layouts/item" + end + + def test_layout_except_exception_when_excepted + @controller = ExceptLayoutController.new + get :goodbye + assert !@response.body.include?("item.erb"), "#{@response.body.inspect} included 'item.erb'" + end + + def test_layout_set_when_using_render + @controller = SetsLayoutInRenderController.new + get :hello + assert_template :layout => "layouts/third_party_template_library" + end + + def test_layout_is_not_set_when_none_rendered + @controller = RendersNoLayoutController.new + get :hello + assert_template :layout => nil + end + + def test_layout_is_picked_from_the_controller_instances_view_path + @controller = PrependsViewPathController.new + get :hello + assert_template :layout => /layouts\/alt/ + end + + def test_absolute_pathed_layout + @controller = AbsolutePathLayoutController.new + get :hello + assert_equal "layout_test.erb hello.erb", @response.body.strip + end +end + +class RenderWithTemplateOptionController < LayoutTest + def hello + render :template => 'alt/hello' + end +end + +class SetsNonExistentLayoutFile < LayoutTest + layout "nofile" +end + +class LayoutExceptionRaisedTest < ActionController::TestCase + def test_exception_raised_when_layout_file_not_found + @controller = SetsNonExistentLayoutFile.new + assert_raise(ActionView::MissingTemplate) { get :hello } + end +end + +class LayoutStatusIsRendered < LayoutTest + def hello + render :status => 401 + end +end + +class LayoutStatusIsRenderedTest < ActionController::TestCase + def test_layout_status_is_rendered + @controller = LayoutStatusIsRendered.new + get :hello + assert_response 401 + end +end + +unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ + 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 + assert_template :layout => "layouts/symlinked/symlinked_layout" + end + end +end diff --git a/actionview/test/fixtures/actionpack/layout_tests/alt/layouts/alt.erb b/actionview/test/fixtures/actionpack/layout_tests/alt/layouts/alt.erb new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/actionview/test/fixtures/actionpack/layout_tests/alt/layouts/alt.erb diff --git a/actionview/test/fixtures/actionpack/layout_tests/layouts/controller_name_space/nested.erb b/actionview/test/fixtures/actionpack/layout_tests/layouts/controller_name_space/nested.erb new file mode 100644 index 0000000000..121bc079a1 --- /dev/null +++ b/actionview/test/fixtures/actionpack/layout_tests/layouts/controller_name_space/nested.erb @@ -0,0 +1 @@ +controller_name_space/nested.erb <%= yield %>
\ No newline at end of file diff --git a/actionview/test/fixtures/actionpack/layout_tests/layouts/item.erb b/actionview/test/fixtures/actionpack/layout_tests/layouts/item.erb new file mode 100644 index 0000000000..60f04d77d5 --- /dev/null +++ b/actionview/test/fixtures/actionpack/layout_tests/layouts/item.erb @@ -0,0 +1 @@ +item.erb <%= yield %>
\ No newline at end of file diff --git a/actionview/test/fixtures/actionpack/layout_tests/layouts/layout_test.erb b/actionview/test/fixtures/actionpack/layout_tests/layouts/layout_test.erb new file mode 100644 index 0000000000..b74ac0840d --- /dev/null +++ b/actionview/test/fixtures/actionpack/layout_tests/layouts/layout_test.erb @@ -0,0 +1 @@ +layout_test.erb <%= yield %>
\ No newline at end of file diff --git a/actionview/test/fixtures/actionpack/layout_tests/layouts/multiple_extensions.html.erb b/actionview/test/fixtures/actionpack/layout_tests/layouts/multiple_extensions.html.erb new file mode 100644 index 0000000000..3b65e54f9c --- /dev/null +++ b/actionview/test/fixtures/actionpack/layout_tests/layouts/multiple_extensions.html.erb @@ -0,0 +1 @@ +multiple_extensions.html.erb <%= yield %> diff --git a/actionview/test/fixtures/actionpack/layout_tests/layouts/symlinked/symlinked_layout.erb b/actionview/test/fixtures/actionpack/layout_tests/layouts/symlinked/symlinked_layout.erb new file mode 100644 index 0000000000..bda57d0fae --- /dev/null +++ b/actionview/test/fixtures/actionpack/layout_tests/layouts/symlinked/symlinked_layout.erb @@ -0,0 +1,5 @@ +This is my layout + +<%= yield %> + +End. diff --git a/actionview/test/fixtures/actionpack/layout_tests/layouts/third_party_template_library.mab b/actionview/test/fixtures/actionpack/layout_tests/layouts/third_party_template_library.mab new file mode 100644 index 0000000000..fcee620d82 --- /dev/null +++ b/actionview/test/fixtures/actionpack/layout_tests/layouts/third_party_template_library.mab @@ -0,0 +1 @@ +layouts/third_party_template_library.mab
\ No newline at end of file diff --git a/actionview/test/fixtures/actionpack/layout_tests/views/goodbye.erb b/actionview/test/fixtures/actionpack/layout_tests/views/goodbye.erb new file mode 100644 index 0000000000..4ee911188e --- /dev/null +++ b/actionview/test/fixtures/actionpack/layout_tests/views/goodbye.erb @@ -0,0 +1 @@ +hello.erb
\ No newline at end of file diff --git a/actionview/test/fixtures/actionpack/layout_tests/views/hello.erb b/actionview/test/fixtures/actionpack/layout_tests/views/hello.erb new file mode 100644 index 0000000000..4ee911188e --- /dev/null +++ b/actionview/test/fixtures/actionpack/layout_tests/views/hello.erb @@ -0,0 +1 @@ +hello.erb
\ No newline at end of file diff --git a/actionview/test/fixtures/actionpack/layouts/_column.html.erb b/actionview/test/fixtures/actionpack/layouts/_column.html.erb new file mode 100644 index 0000000000..96db002b8a --- /dev/null +++ b/actionview/test/fixtures/actionpack/layouts/_column.html.erb @@ -0,0 +1,2 @@ +<div id="column"><%= yield :column %></div> +<div id="content"><%= yield %></div>
\ No newline at end of file diff --git a/actionview/test/fixtures/actionpack/layouts/_partial_and_yield.erb b/actionview/test/fixtures/actionpack/layouts/_partial_and_yield.erb new file mode 100644 index 0000000000..74cc428ffa --- /dev/null +++ b/actionview/test/fixtures/actionpack/layouts/_partial_and_yield.erb @@ -0,0 +1,2 @@ +<%= render :partial => 'test/partial' %> +<%= yield %> diff --git a/actionview/test/fixtures/actionpack/layouts/_yield_only.erb b/actionview/test/fixtures/actionpack/layouts/_yield_only.erb new file mode 100644 index 0000000000..37f0bddbd7 --- /dev/null +++ b/actionview/test/fixtures/actionpack/layouts/_yield_only.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/actionview/test/fixtures/actionpack/layouts/_yield_with_params.erb b/actionview/test/fixtures/actionpack/layouts/_yield_with_params.erb new file mode 100644 index 0000000000..68e6557fb8 --- /dev/null +++ b/actionview/test/fixtures/actionpack/layouts/_yield_with_params.erb @@ -0,0 +1 @@ +<%= yield 'Yield!' %> diff --git a/actionview/test/fixtures/actionpack/layouts/streaming.erb b/actionview/test/fixtures/actionpack/layouts/streaming.erb new file mode 100644 index 0000000000..d3f896a6ca --- /dev/null +++ b/actionview/test/fixtures/actionpack/layouts/streaming.erb @@ -0,0 +1,4 @@ +<%= yield :header -%> +<%= yield -%> +<%= yield :footer -%> +<%= yield(:unknown).presence || "." -%>
\ No newline at end of file diff --git a/actionview/test/fixtures/actionpack/layouts/yield_with_render_inline_inside.erb b/actionview/test/fixtures/actionpack/layouts/yield_with_render_inline_inside.erb new file mode 100644 index 0000000000..7298d79690 --- /dev/null +++ b/actionview/test/fixtures/actionpack/layouts/yield_with_render_inline_inside.erb @@ -0,0 +1,2 @@ +<%= render :inline => 'welcome' %> +<%= yield %> diff --git a/actionview/test/fixtures/actionpack/layouts/yield_with_render_partial_inside.erb b/actionview/test/fixtures/actionpack/layouts/yield_with_render_partial_inside.erb new file mode 100644 index 0000000000..74cc428ffa --- /dev/null +++ b/actionview/test/fixtures/actionpack/layouts/yield_with_render_partial_inside.erb @@ -0,0 +1,2 @@ +<%= render :partial => 'test/partial' %> +<%= yield %> |