From 893e9eb99504705419ad6edac14d00e71cef5f12 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 9 Feb 2009 14:20:30 -0600 Subject: Improve view rendering performance in development mode and reinstate template recompiling in production [#1909 state:resolved] Signed-off-by: Joshua Peek --- .../test/template/compiled_templates_test.rb | 42 ++++++++++++---------- actionpack/test/template/render_test.rb | 15 +------- 2 files changed, 24 insertions(+), 33 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index a7ed13cf57..2c32fdee0b 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -39,35 +39,29 @@ class CompiledTemplatesTest < Test::Unit::TestCase end def test_template_changes_are_not_reflected_with_cached_templates - assert_equal "Hello world!", render(:file => "test/hello_world.erb") - modify_template "test/hello_world.erb", "Goodbye world!" do + with_caching(true) do + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + modify_template "test/hello_world.erb", "Goodbye world!" do + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + end assert_equal "Hello world!", render(:file => "test/hello_world.erb") end - assert_equal "Hello world!", render(:file => "test/hello_world.erb") end - def test_template_changes_are_reflected_with_uncached_templates - assert_equal "Hello world!", render_without_cache(:file => "test/hello_world.erb") - modify_template "test/hello_world.erb", "Goodbye world!" do - assert_equal "Goodbye world!", render_without_cache(:file => "test/hello_world.erb") + def test_template_changes_are_reflected_without_cached_templates + with_caching(false) do + assert_equal "Hello world!", render(:file => "test/hello_world.erb") + modify_template "test/hello_world.erb", "Goodbye world!" do + assert_equal "Goodbye world!", render(:file => "test/hello_world.erb") + sleep(1) # Need to sleep so that the timestamp actually changes + end + assert_equal "Hello world!", render(:file => "test/hello_world.erb") end - assert_equal "Hello world!", render_without_cache(:file => "test/hello_world.erb") end private def render(*args) - render_with_cache(*args) - end - - def render_with_cache(*args) view_paths = ActionController::Base.view_paths - assert_equal ActionView::Template::EagerPath, view_paths.first.class - ActionView::Base.new(view_paths, {}).render(*args) - end - - def render_without_cache(*args) - path = ActionView::Template::Path.new(FIXTURE_LOAD_PATH) - view_paths = ActionView::Base.process_view_paths(path) assert_equal ActionView::Template::Path, view_paths.first.class ActionView::Base.new(view_paths, {}).render(*args) end @@ -82,4 +76,14 @@ class CompiledTemplatesTest < Test::Unit::TestCase File.open(filename, "wb+") { |f| f.write(old_content) } end end + + def with_caching(caching_enabled) + old_caching_enabled = ActionView::Base.cache_template_loading + begin + ActionView::Base.cache_template_loading = caching_enabled + yield + ensure + ActionView::Base.cache_template_loading = old_caching_enabled + end + end end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 9db62d9c23..34e7e82366 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -243,25 +243,12 @@ module RenderTestCases end end -class CachedViewRenderTest < Test::Unit::TestCase +class CachedRenderTest < Test::Unit::TestCase include RenderTestCases # Ensure view path cache is primed def setup view_paths = ActionController::Base.view_paths - assert_equal ActionView::Template::EagerPath, view_paths.first.class - setup_view(view_paths) - end -end - -class LazyViewRenderTest < Test::Unit::TestCase - include RenderTestCases - - # Test the same thing as above, but make sure the view path - # is not eager loaded - def setup - path = ActionView::Template::Path.new(FIXTURE_LOAD_PATH) - view_paths = ActionView::Base.process_view_paths(path) assert_equal ActionView::Template::Path, view_paths.first.class setup_view(view_paths) end -- cgit v1.2.3