diff options
author | Stefan Kaes <stkaes@googlemail.com> | 2008-07-16 08:26:23 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-07-16 08:26:23 -0500 |
commit | c64d749abdf31a2be322b1787165024067abbda7 (patch) | |
tree | 5289a0ecb600d7e92d4c5fce4e2b3c7147483452 /actionpack/test | |
parent | 0432d151647f2178ddee79979827d552447c251f (diff) | |
download | rails-c64d749abdf31a2be322b1787165024067abbda7.tar.gz rails-c64d749abdf31a2be322b1787165024067abbda7.tar.bz2 rails-c64d749abdf31a2be322b1787165024067abbda7.zip |
Fixed template recompile logic [#630 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/abstract_unit.rb | 1 | ||||
-rw-r--r-- | actionpack/test/template/compiled_templates_test.rb | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 520379fe82..9db4cddd6a 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -23,6 +23,7 @@ ActionController::Base.logger = nil ActionController::Routing::Routes.reload rescue nil FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') +ActionView::PathSet::Path.eager_load_templates! ActionController::Base.view_paths = FIXTURE_LOAD_PATH # Wrap tests that use Mocha and skip if unavailable. diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb new file mode 100644 index 0000000000..4b34827f91 --- /dev/null +++ b/actionpack/test/template/compiled_templates_test.rb @@ -0,0 +1,41 @@ +require 'abstract_unit' +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_/ + end + end + + 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 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 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") + ActionView::Template.any_instance.expects(:compile!).never + assert_equal "Hello world!", @view.render("test/hello_world.erb") + end + + def test_compiled_template_will_always_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") } + end + end +end |