Skip to content
Browse files

Add some unit tests to Template#refresh.

  • Loading branch information...
1 parent cba395d commit ffa32714bd339ae32355a6827750e1af81454a1b @josevalim josevalim committed Oct 10, 2010
Showing with 28 additions and 4 deletions.
  1. +28 −4 actionpack/test/template/template_test.rb
View
32 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 @@ def partial
)
end
+ def lookup_context
+ @lookup_context ||= LookupContext.new
+ end
+
def logger
- require "logger"
Logger.new(STDERR)
end
@@ -37,11 +47,11 @@ def new_template(body = "<%= hello %>", details = {})
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 @@ def test_locals
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 @@ def test_virtual_path
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

0 comments on commit ffa3271

Please sign in to comment.
Something went wrong with that request. Please try again.