diff options
author | José Valim <jose.valim@gmail.com> | 2010-10-10 13:17:01 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-10-10 13:17:04 +0200 |
commit | ffa32714bd339ae32355a6827750e1af81454a1b (patch) | |
tree | 9663ebb516cb396861f719d1892e7f901007b7a3 /actionpack/test | |
parent | cba395dab9812d86d48cc0574061cd6dcd18009b (diff) | |
download | rails-ffa32714bd339ae32355a6827750e1af81454a1b.tar.gz rails-ffa32714bd339ae32355a6827750e1af81454a1b.tar.bz2 rails-ffa32714bd339ae32355a6827750e1af81454a1b.zip |
Add some unit tests to Template#refresh.
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/template/template_test.rb | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index eb2d4aab36..34679962b2 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -1,9 +1,16 @@ require "abstract_unit" +require "logger" class TestERBTemplate < ActiveSupport::TestCase ERBHandler = ActionView::Template::Handlers::ERB.new class Context + class LookupContext + def disable_cache + yield + end + end + def initialize @output_buffer = "original" @_virtual_path = nil @@ -22,8 +29,11 @@ class TestERBTemplate < ActiveSupport::TestCase ) end + def lookup_context + @lookup_context ||= LookupContext.new + end + def logger - require "logger" Logger.new(STDERR) end @@ -37,11 +47,11 @@ class TestERBTemplate < ActiveSupport::TestCase end def render(locals = {}) - @template.render(@obj, locals) + @template.render(@context, locals) end def setup - @obj = Context.new + @context = Context.new end def test_basic_template @@ -70,7 +80,7 @@ class TestERBTemplate < ActiveSupport::TestCase def test_restores_buffer @template = new_template assert_equal "Hello", render - assert_equal "original", @obj.my_buffer + assert_equal "original", @context.my_buffer end def test_virtual_path @@ -80,6 +90,20 @@ class TestERBTemplate < ActiveSupport::TestCase assert_equal "hellopartialhello", render end + def test_refresh + @template = new_template("Hello", :virtual_path => "test/foo") + @template.locals = [:key] + @context.lookup_context.expects(:find_template).with("foo", "test", false, [:key]).returns("template") + assert_equal "template", @template.refresh(@context) + end + + def test_refresh_raises_an_error_without_virtual_path + @template = new_template("Hello", :virtual_path => nil) + assert_raise RuntimeError, /OMG/ do + @template.refresh(@context) + end + end + if "ruby".encoding_aware? def test_resulting_string_is_utf8 @template = new_template |