aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2009-02-09 14:20:30 -0600
committerJoshua Peek <josh@joshpeek.com>2009-02-09 14:20:30 -0600
commit893e9eb99504705419ad6edac14d00e71cef5f12 (patch)
tree17a2c15b63335beb97ecfea5ca6ca5a776639fa5 /actionpack/test
parent5120429c3138d46490a1c4a611ebd93410f4f885 (diff)
downloadrails-893e9eb99504705419ad6edac14d00e71cef5f12.tar.gz
rails-893e9eb99504705419ad6edac14d00e71cef5f12.tar.bz2
rails-893e9eb99504705419ad6edac14d00e71cef5f12.zip
Improve view rendering performance in development mode and reinstate template recompiling in production [#1909 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/template/compiled_templates_test.rb42
-rw-r--r--actionpack/test/template/render_test.rb15
2 files changed, 24 insertions, 33 deletions
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