aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/actionpack/controller/layout_test.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-06-12 14:06:59 +0200
committerYves Senn <yves.senn@gmail.com>2014-06-12 14:06:59 +0200
commit8f247871bb18b2e3036a05df5f62cbfe3b402586 (patch)
tree1e4c8b4b9ccd82f4effe1949b5c116254223e91a /actionview/test/actionpack/controller/layout_test.rb
parent2a7580e63cdcc9cf1c8837578b1d18602db2b74c (diff)
parenta1dbb4e7e0a580e013423c7adf8ba3127c4c59e0 (diff)
downloadrails-8f247871bb18b2e3036a05df5f62cbfe3b402586.tar.gz
rails-8f247871bb18b2e3036a05df5f62cbfe3b402586.tar.bz2
rails-8f247871bb18b2e3036a05df5f62cbfe3b402586.zip
Merge pull request #15590 from zuhao/refactor_actionview_register_template_handler
Add unregister_template_handler to prevent leaks. Conflicts: actionview/CHANGELOG.md
Diffstat (limited to 'actionview/test/actionpack/controller/layout_test.rb')
-rw-r--r--actionview/test/actionpack/controller/layout_test.rb33
1 files changed, 23 insertions, 10 deletions
diff --git a/actionview/test/actionpack/controller/layout_test.rb b/actionview/test/actionpack/controller/layout_test.rb
index b44f57a23e..bd345fe873 100644
--- a/actionview/test/actionpack/controller/layout_test.rb
+++ b/actionview/test/actionpack/controller/layout_test.rb
@@ -6,9 +6,6 @@ require 'active_support/core_ext/array/extract_options'
# 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
@@ -17,6 +14,15 @@ class LayoutTest < ActionController::Base
self.view_paths = ActionController::Base.view_paths.dup
end
+module TemplateHandlerHelper
+ def with_template_handler(*extensions, handler)
+ ActionView::Template.register_template_handler(*extensions, handler)
+ yield
+ ensure
+ ActionView::Template.unregister_template_handler(*extensions)
+ end
+end
+
# Restore view_paths to previous value
ActionController::Base.view_paths = old_load_paths
@@ -39,6 +45,8 @@ class MultipleExtensions < LayoutTest
end
class LayoutAutoDiscoveryTest < ActionController::TestCase
+ include TemplateHandlerHelper
+
def setup
super
@request.host = "www.nextangle.com"
@@ -57,10 +65,12 @@ class LayoutAutoDiscoveryTest < ActionController::TestCase
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
+ with_template_handler :mab, lambda { |template| template.source.inspect } do
+ @controller = ThirdPartyTemplateLibraryController.new
+ get :hello
+ assert_response :success
+ assert_equal 'layouts/third_party_template_library.mab', @response.body
+ end
end
def test_namespaced_controllers_auto_detect_layouts1
@@ -135,6 +145,7 @@ end
class LayoutSetInResponseTest < ActionController::TestCase
include ActionView::Template::Handlers
+ include TemplateHandlerHelper
def test_layout_set_when_using_default_layout
@controller = DefaultLayoutController.new
@@ -191,9 +202,11 @@ class LayoutSetInResponseTest < ActionController::TestCase
end
def test_layout_set_when_using_render
- @controller = SetsLayoutInRenderController.new
- get :hello
- assert_template :layout => "layouts/third_party_template_library"
+ with_template_handler :mab, lambda { |template| template.source.inspect } do
+ @controller = SetsLayoutInRenderController.new
+ get :hello
+ assert_template :layout => "layouts/third_party_template_library"
+ end
end
def test_layout_is_not_set_when_none_rendered