aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/compiled_templates_test.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2009-02-10 12:09:49 -0600
committerJoshua Peek <josh@joshpeek.com>2009-02-10 12:09:49 -0600
commit199e750d46c04970b5e7684998d09405648ecbd4 (patch)
tree97f847ba98946ac2da003831042966afb1017268 /actionpack/test/template/compiled_templates_test.rb
parent1dab1d380377f1a2a60da43bc22989d55632d246 (diff)
downloadrails-199e750d46c04970b5e7684998d09405648ecbd4.tar.gz
rails-199e750d46c04970b5e7684998d09405648ecbd4.tar.bz2
rails-199e750d46c04970b5e7684998d09405648ecbd4.zip
Fix some edge cases when the same template is called with different local assigns
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack/test/template/compiled_templates_test.rb')
-rw-r--r--actionpack/test/template/compiled_templates_test.rb86
1 files changed, 54 insertions, 32 deletions
diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb
index 2c32fdee0b..55fa346fb8 100644
--- a/actionpack/test/template/compiled_templates_test.rb
+++ b/actionpack/test/template/compiled_templates_test.rb
@@ -10,52 +10,64 @@ class CompiledTemplatesTest < Test::Unit::TestCase
end
def test_template_gets_compiled
- assert_equal 0, @compiled_templates.instance_methods.size
- assert_equal "Hello world!", render(:file => "test/hello_world.erb")
- assert_equal 1, @compiled_templates.instance_methods.size
+ with_caching(true) do
+ assert_equal 0, @compiled_templates.instance_methods.size
+ assert_equal "Hello world!", render(:file => "test/hello_world.erb")
+ assert_equal 1, @compiled_templates.instance_methods.size
+ end
end
def test_template_gets_recompiled_when_using_different_keys_in_local_assigns
- assert_equal 0, @compiled_templates.instance_methods.size
- assert_equal "Hello world!", render(:file => "test/hello_world.erb")
- assert_equal "Hello world!", render(:file => "test/hello_world.erb", :locals => {:foo => "bar"})
- assert_equal 2, @compiled_templates.instance_methods.size
+ with_caching(true) do
+ assert_equal 0, @compiled_templates.instance_methods.size
+ assert_equal "Hello world!", render(:file => "test/hello_world.erb")
+ assert_equal "Hello world!", render(:file => "test/hello_world.erb", :locals => {:foo => "bar"})
+ assert_equal 2, @compiled_templates.instance_methods.size
+ end
end
def test_compiled_template_will_not_be_recompiled_when_rendered_with_identical_local_assigns
- assert_equal 0, @compiled_templates.instance_methods.size
- assert_equal "Hello world!", render(:file => "test/hello_world.erb")
- ActionView::Template.any_instance.expects(:compile!).never
- assert_equal "Hello world!", render(:file => "test/hello_world.erb")
+ with_caching(true) do
+ assert_equal 0, @compiled_templates.instance_methods.size
+ assert_equal "Hello world!", render(:file => "test/hello_world.erb")
+ ActionView::Template.any_instance.expects(:compile!).never
+ assert_equal "Hello world!", render(:file => "test/hello_world.erb")
+ end
end
def test_compiled_template_will_always_be_recompiled_when_template_is_not_cached
- ActionView::Template.any_instance.expects(:recompile?).times(3).returns(true)
- assert_equal 0, @compiled_templates.instance_methods.size
- assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb")
- ActionView::Template.any_instance.expects(:compile!).times(3)
- 3.times { assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") }
- assert_equal 1, @compiled_templates.instance_methods.size
+ with_caching(false) do
+ ActionView::Template.any_instance.expects(:recompile?).times(3).returns(true)
+ assert_equal 0, @compiled_templates.instance_methods.size
+ assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb")
+ ActionView::Template.any_instance.expects(:compile!).times(3)
+ 3.times { assert_equal "Hello world!", render(:file => "#{FIXTURE_LOAD_PATH}/test/hello_world.erb") }
+ assert_equal 1, @compiled_templates.instance_methods.size
+ end
end
- def test_template_changes_are_not_reflected_with_cached_templates
+ def test_template_changes_are_not_reflected_with_cached_template_loading
with_caching(true) do
- assert_equal "Hello world!", render(:file => "test/hello_world.erb")
- modify_template "test/hello_world.erb", "Goodbye world!" do
+ with_reloading(false) 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
end
- 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
+ def test_template_changes_are_reflected_without_cached_template_loading
+ with_caching(true) do
+ with_reloading(true) 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(:file => "test/hello_world.erb")
end
end
@@ -77,13 +89,23 @@ class CompiledTemplatesTest < Test::Unit::TestCase
end
end
- def with_caching(caching_enabled)
- old_caching_enabled = ActionView::Base.cache_template_loading
+ def with_caching(perform_caching)
+ old_perform_caching = ActionController::Base.perform_caching
+ begin
+ ActionController::Base.perform_caching = perform_caching
+ yield
+ ensure
+ ActionController::Base.perform_caching = old_perform_caching
+ end
+ end
+
+ def with_reloading(reload_templates)
+ old_cache_template_loading = ActionView::Base.cache_template_loading
begin
- ActionView::Base.cache_template_loading = caching_enabled
+ ActionView::Base.cache_template_loading = !reload_templates
yield
ensure
- ActionView::Base.cache_template_loading = old_caching_enabled
+ ActionView::Base.cache_template_loading = old_cache_template_loading
end
end
end