Skip to content
This repository
Browse code

Add some unit tests to Template#refresh.

  • Loading branch information...
commit ffa32714bd339ae32355a6827750e1af81454a1b 1 parent cba395d
José Valim josevalim authored

Showing 1 changed file with 28 additions and 4 deletions. Show diff stats Hide diff stats

  1. +28 4 actionpack/test/template/template_test.rb
32 actionpack/test/template/template_test.rb
... ... @@ -1,9 +1,16 @@
1 1 require "abstract_unit"
  2 +require "logger"
2 3
3 4 class TestERBTemplate < ActiveSupport::TestCase
4 5 ERBHandler = ActionView::Template::Handlers::ERB.new
5 6
6 7 class Context
  8 + class LookupContext
  9 + def disable_cache
  10 + yield
  11 + end
  12 + end
  13 +
7 14 def initialize
8 15 @output_buffer = "original"
9 16 @_virtual_path = nil
@@ -22,8 +29,11 @@ def partial
22 29 )
23 30 end
24 31
  32 + def lookup_context
  33 + @lookup_context ||= LookupContext.new
  34 + end
  35 +
25 36 def logger
26   - require "logger"
27 37 Logger.new(STDERR)
28 38 end
29 39
@@ -37,11 +47,11 @@ def new_template(body = "<%= hello %>", details = {})
37 47 end
38 48
39 49 def render(locals = {})
40   - @template.render(@obj, locals)
  50 + @template.render(@context, locals)
41 51 end
42 52
43 53 def setup
44   - @obj = Context.new
  54 + @context = Context.new
45 55 end
46 56
47 57 def test_basic_template
@@ -70,7 +80,7 @@ def test_locals
70 80 def test_restores_buffer
71 81 @template = new_template
72 82 assert_equal "Hello", render
73   - assert_equal "original", @obj.my_buffer
  83 + assert_equal "original", @context.my_buffer
74 84 end
75 85
76 86 def test_virtual_path
@@ -80,6 +90,20 @@ def test_virtual_path
80 90 assert_equal "hellopartialhello", render
81 91 end
82 92
  93 + def test_refresh
  94 + @template = new_template("Hello", :virtual_path => "test/foo")
  95 + @template.locals = [:key]
  96 + @context.lookup_context.expects(:find_template).with("foo", "test", false, [:key]).returns("template")
  97 + assert_equal "template", @template.refresh(@context)
  98 + end
  99 +
  100 + def test_refresh_raises_an_error_without_virtual_path
  101 + @template = new_template("Hello", :virtual_path => nil)
  102 + assert_raise RuntimeError, /OMG/ do
  103 + @template.refresh(@context)
  104 + end
  105 + end
  106 +
83 107 if "ruby".encoding_aware?
84 108 def test_resulting_string_is_utf8
85 109 @template = new_template

0 comments on commit ffa3271

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