From d6bac046922fcee05366d26d75349dde70d25f6b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 17 May 2016 11:28:40 -0700 Subject: keep layouts + locals from bloating the cache Using locals will cause layouts to be cached multiple times in the template cache. This commit removes locals from consideration when looking up the layout. --- actionview/test/actionpack/abstract/layouts_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'actionview/test/actionpack/abstract') diff --git a/actionview/test/actionpack/abstract/layouts_test.rb b/actionview/test/actionpack/abstract/layouts_test.rb index 8c80a2d2cf..72765dc7f5 100644 --- a/actionview/test/actionpack/abstract/layouts_test.rb +++ b/actionview/test/actionpack/abstract/layouts_test.rb @@ -224,6 +224,25 @@ module AbstractControllerTests assert_equal "With String hello less than 3 bar", controller.response_body end + test "cache should not grow when locals change for a string template" do + cache = WithString.view_paths.paths.first.instance_variable_get(:@cache) + + controller = WithString.new + controller.process(:index) # heat the cache + + size = cache.size + + 10.times do |x| + controller = WithString.new + controller.define_singleton_method :index do + render :template => ActionView::Template::Text.new("Hello string!"), :locals => { :"x#{x}" => :omg } + end + controller.process(:index) + end + + assert_equal size, cache.size + end + test "when layout is specified as a string, render with that layout" do controller = WithString.new controller.process(:index) -- cgit v1.2.3