diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-07-22 10:27:32 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-07-22 10:27:32 -0500 |
commit | bc5896e708bf8070835bebe61de03b701fa5e6f7 (patch) | |
tree | e244324bec641c94eca09b25bb9decba0f4699c0 /actionpack/test/template | |
parent | 8a87d8a6c2c6dfb423bcaf61c750010d80993b16 (diff) | |
download | rails-bc5896e708bf8070835bebe61de03b701fa5e6f7.tar.gz rails-bc5896e708bf8070835bebe61de03b701fa5e6f7.tar.bz2 rails-bc5896e708bf8070835bebe61de03b701fa5e6f7.zip |
Memoize ActionView::Base pick_template and find_partial_path for rendering duration
Diffstat (limited to 'actionpack/test/template')
-rw-r--r-- | actionpack/test/template/compiled_templates_test.rb | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index 4b34827f91..52996c7fcb 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -4,7 +4,6 @@ require 'controller/fake_models' uses_mocha 'TestTemplateRecompilation' do class CompiledTemplatesTest < Test::Unit::TestCase def setup - @view = ActionView::Base.new(ActionController::Base.view_paths, {}) @compiled_templates = ActionView::Base::CompiledTemplates @compiled_templates.instance_methods.each do |m| @compiled_templates.send(:remove_method, m) if m =~ /^_run_/ @@ -13,29 +12,33 @@ uses_mocha 'TestTemplateRecompilation' do def test_template_gets_compiled assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", @view.render("test/hello_world.erb") + assert_equal "Hello world!", render("test/hello_world.erb") assert_equal 1, @compiled_templates.instance_methods.size 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!", @view.render("test/hello_world.erb") - assert_equal "Hello world!", @view.render("test/hello_world.erb", {:foo => "bar"}) + assert_equal "Hello world!", render("test/hello_world.erb") + assert_equal "Hello world!", render("test/hello_world.erb", {:foo => "bar"}) assert_equal 2, @compiled_templates.instance_methods.size 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!", @view.render("test/hello_world.erb") + assert_equal "Hello world!", render("test/hello_world.erb") ActionView::Template.any_instance.expects(:compile!).never - assert_equal "Hello world!", @view.render("test/hello_world.erb") + assert_equal "Hello world!", render("test/hello_world.erb") end - def test_compiled_template_will_always_be_recompiled_when_rendered_if_template_is_outside_cache + def test_compiled_template_will_be_recompiled_when_rendered_if_template_is_outside_cache assert_equal 0, @compiled_templates.instance_methods.size - assert_equal "Hello world!", @view.render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") - ActionView::Template.any_instance.expects(:compile!).times(3) - 3.times { assert_equal "Hello world!", @view.render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") } + assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") + assert_equal 1, @compiled_templates.instance_methods.size end + + private + def render(*args) + ActionView::Base.new(ActionController::Base.view_paths, {}).render(*args) + end end end |