1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add some unit tests to Template#refresh.

This commit is contained in:
José Valim 2010-10-10 13:17:01 +02:00
parent cba395dab9
commit ffa32714bd

View file

@ -1,9 +1,16 @@
require "abstract_unit" require "abstract_unit"
require "logger"
class TestERBTemplate < ActiveSupport::TestCase class TestERBTemplate < ActiveSupport::TestCase
ERBHandler = ActionView::Template::Handlers::ERB.new ERBHandler = ActionView::Template::Handlers::ERB.new
class Context class Context
class LookupContext
def disable_cache
yield
end
end
def initialize def initialize
@output_buffer = "original" @output_buffer = "original"
@_virtual_path = nil @_virtual_path = nil
@ -22,8 +29,11 @@ class TestERBTemplate < ActiveSupport::TestCase
) )
end end
def lookup_context
@lookup_context ||= LookupContext.new
end
def logger def logger
require "logger"
Logger.new(STDERR) Logger.new(STDERR)
end end
@ -37,11 +47,11 @@ class TestERBTemplate < ActiveSupport::TestCase
end end
def render(locals = {}) def render(locals = {})
@template.render(@obj, locals) @template.render(@context, locals)
end end
def setup def setup
@obj = Context.new @context = Context.new
end end
def test_basic_template def test_basic_template
@ -70,7 +80,7 @@ class TestERBTemplate < ActiveSupport::TestCase
def test_restores_buffer def test_restores_buffer
@template = new_template @template = new_template
assert_equal "Hello", render assert_equal "Hello", render
assert_equal "original", @obj.my_buffer assert_equal "original", @context.my_buffer
end end
def test_virtual_path def test_virtual_path
@ -80,6 +90,20 @@ class TestERBTemplate < ActiveSupport::TestCase
assert_equal "hellopartialhello", render assert_equal "hellopartialhello", render
end 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? if "ruby".encoding_aware?
def test_resulting_string_is_utf8 def test_resulting_string_is_utf8
@template = new_template @template = new_template